Beispiel #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());
                }
            });
        }
Beispiel #2
0
        public void CanEncryptSecureString()
        {
            var value = ORIGINAL_VALUE.Secure();

            var result = new SecureStringSecurity().EncryptValue(value, _password, Defaults.SALTSIZE, Defaults.ITERATIONS);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Length != 0);
        }
Beispiel #3
0
        public void EncryptedValuesCanBeDecryptedAsSecureString()
        {
            var result = Security.Encrypt(_value, _password, Defaults.SALTSIZE, Defaults.ITERATIONS);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Length != 0);


            var stringResult = new SecureStringSecurity().DecryptValue(result, _password, Defaults.ITERATIONS);

            Assert.IsNotNull(stringResult);
            Assert.IsTrue(stringResult.Length != 0);
            Assert.AreEqual(ORIGINAL_VALUE, stringResult.ToUnsecureString());
        }
Beispiel #4
0
        public void CanEncryptDictionaryWithEncryptedKeys()
        {
            var value = ORIGINAL_VALUE.Secure();

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

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

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Length != 0);
        }
Beispiel #5
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());
            });
        }