Beispiel #1
0
        public void Decrypt_Should_Decode_An_Encrypted_String_With_Special_Characters()
        {
            // arrange
            var key             = Guid.NewGuid().ToString("N");
            var salt            = Guid.NewGuid().ToString("N");
            var original_value  = "Søm€ unicode s-tring+";
            var encrypted_value = CryptographyHelpers.Encrypt(key, salt, original_value);

            // act
            var target = CryptographyHelpers.Decrypt(key, salt, encrypted_value);

            // assert
            target.Should().NotBeNullOrEmpty();
            target.Should().Be(original_value);
        }
Beispiel #2
0
        public void Decrypt_Should_Decode_An_Encrypted_String()
        {
            // arrange
            var key             = Guid.NewGuid().ToString();
            var salt            = Guid.NewGuid().ToString();
            var original_value  = "lorem ipsum dom dolor sit amet";
            var encrypted_value = CryptographyHelpers.Encrypt(key, salt, original_value);

            // act
            var target = CryptographyHelpers.Decrypt(key, salt, encrypted_value);

            // assert
            target.Should().NotBeNullOrEmpty();
            target.Should().Be(original_value);
        }
        /// <summary>
        /// Gets a strong typed object from the LocalStorage.
        /// </summary>
        /// <param name="key">Unique key, as used when the object was stored.</param>
        public T Get <T>(string key)
        {
            var succeeded = Storage.TryGetValue(key, out string raw);

            if (!succeeded)
            {
                throw new ArgumentNullException($"Could not find key '{key}' in the LocalStorage.");
            }

            if (_config.EnableEncryption)
            {
                raw = CryptographyHelpers.Decrypt(_encryptionKey, _config.EncryptionSalt, raw);
            }

            return(JsonConvert.DeserializeObject <T>(raw));
        }