예제 #1
0
        /// <summary>
        /// Constructs the values.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <returns></returns>
        private NameValueCollection ConstructValues(IConfigContainer container)
        {
            var values = new NameValueCollection();
            var xNodes = container.Node.GetNodes(_sectionXPath);

            if (xNodes == null)
            {
                return(values);
            }

            foreach (XmlNode xNode in xNodes)
            {
                var xKey   = xNode.Attributes["key"];
                var xValue = xNode.Attributes["value"];
                if (xKey == null || xValue == null)
                {
                    continue;
                }

                var xSecure = xNode.Attributes["secure"];
                var secure  = EncryptionProvider != null && xSecure != null && xSecure.Value.ToLower() == "true";

                values[xKey.Value] = secure ? EncryptionProvider.DecryptString(xValue.Value, Encoding.UTF8) : xValue.Value;
            }

            return(values);
        }
예제 #2
0
 public string GetString(ISFSObject data, string key)
 {
     if (receiveEncrypted)
     {
         return(provider.DecryptString(data.GetByteArray(key)));
     }
     else
     {
         return(data.GetUtfString(key));
     }
 }
예제 #3
0
        public void EncryptionProviderUniqueIVTest()
        {
            var stringToEncrypt = "Hello World";

            IEncryptionProvider encryptionProvider = new EncryptionProvider();
            var encryptionKeys = encryptionProvider.GenerateSecretKeys();
            var recoveryKey    = encryptionProvider.EncodeSecretKeysToBase64(encryptionKeys);

            encryptionProvider.SetSecretKeys(encryptionKeys);

            var encryptedString  = encryptionProvider.EncryptString(stringToEncrypt);
            var encryptedString2 = encryptionProvider.EncryptString(stringToEncrypt);

            Assert.AreNotEqual(encryptedString, encryptedString2);
            Assert.AreNotEqual(stringToEncrypt, encryptedString);

            encryptionProvider = new EncryptionProvider();
            encryptionKeys     = encryptionProvider.DecodeSecretKeysFromBase64(recoveryKey);
            encryptionProvider.SetSecretKeys(encryptionKeys);

            var decryptedString = encryptionProvider.DecryptString(encryptedString);

            Assert.AreEqual(stringToEncrypt, decryptedString);
        }
예제 #4
0
 public static string LoadSetting(string key)
 {
     return(EncryptionProvider.DecryptString(key));
 }