Example #1
0
        public void EncryptedDictionaryCanBeDecrypted()
        {
            TestAllOptions((options, path) =>
            {
                var value = ORIGINAL_VALUE.Secure();

                var dictionary = new Dictionary <string, SecureString>
                {
                    { "key", value }
                };

                var security = new SecureStringSecurity();
                var result   = security.EncryptDictionary(dictionary, _password, options, Defaults.SALTSIZE, Defaults.ITERATIONS);

                var decrypted = security.DecryptDictionary(result, _password, options, Defaults.ITERATIONS);

                Assert.IsNotNull(decrypted);
                Assert.AreEqual(dictionary.Count, decrypted.Count);
                for (int i = 0; i < dictionary.Count; i++)
                {
                    var expected = dictionary.ElementAt(i);
                    var actual   = decrypted.ElementAt(i);

                    Assert.AreEqual(expected.Key, actual.Key);
                    Assert.AreEqual(expected.Value.Length, actual.Value.Length);
                    Assert.AreEqual(expected.Value.ToUnsecureString(), actual.Value.ToUnsecureString());
                }
            });
        }
Example #2
0
        public void SingleKeyCanBeDecryptedFromADictionary()
        {
            TestAllOptions((options, path) =>
            {
                const string key = "another Key";
                var secureString = ORIGINAL_VALUE2.Secure();
                var dictionary   = new Dictionary <string, SecureString>
                {
                    { "key", ORIGINAL_VALUE.Secure() },
                    { key, secureString }
                };

                var security = new SecureStringSecurity();
                var result   = security.EncryptDictionary(dictionary, _password, options, Defaults.SALTSIZE, Defaults.ITERATIONS);

                var decrypted = security.DecryptDictionary(result, key, _password, options, Defaults.ITERATIONS);

                Assert.IsNotNull(decrypted);
                Assert.AreEqual(secureString.Length, decrypted.Length);
                Assert.AreEqual(secureString.ToUnsecureString(), decrypted.ToUnsecureString());
            });
        }