Exemple #1
0
        /// <summary>
        /// Gets the instance of the configuration, based on a config section parameter
        /// </summary>
        /// <param name="configurationSection">The configuration section</param>
        /// <returns>AESEncryption Configuration</returns>
        public static AESConfiguration GetInstance(string configurationSection)
        {
            if (configurationInstance == null)
            {
                configurationInstance = (AESConfiguration)System.Configuration.ConfigurationManager.GetSection(configurationSection);
            }

            return(configurationInstance);
        }
        /// <summary>
        /// This method decrypts a string using the configuration settings supplied
        /// </summary>
        /// <param name="encryptedString">The encrypted string</param>
        /// <returns>The passed in string, decrypted</returns>
        public string DecryptString(string encryptedString)
        {
            string retVal = string.Empty;

            if (!string.IsNullOrEmpty(encryptedString))
            {
                switch (this.EncryptionMethod)
                {
                case EncryptionMethodOptions.None:
                    retVal = encryptedString;
                    break;

                case EncryptionMethodOptions.AES:
                    AESConfiguration aesconfiguration = AESConfiguration.GetInstance(this.EncryptionSetting);
                    AESManager       aesencryption    = new AESManager(aesconfiguration.EncryptionKey, aesconfiguration.Salt);
                    retVal = aesencryption.Decrypt(encryptedString);
                    break;

                case EncryptionMethodOptions.CertificateKeyFile:
                    KeyFileConfiguration   keyfileConfiguration = KeyFileConfiguration.GetInstance(this.EncryptionSetting);
                    X509CertificateManager keyfileEncryption    = new X509CertificateManager(keyfileConfiguration.KeyFile, keyfileConfiguration.KeyFilePassword);
                    retVal = keyfileEncryption.Decrypt(encryptedString);
                    break;

                case EncryptionMethodOptions.CertificateKeyStore:
                    KeyStoreConfiguration  keystoreConfiguration = KeyStoreConfiguration.GetInstance(this.EncryptionSetting);
                    X509CertificateManager keystoreEncryption    = new X509CertificateManager(keystoreConfiguration.StoreName, keystoreConfiguration.StoreLocation, keystoreConfiguration.CertificateName);
                    retVal = keystoreEncryption.Decrypt(encryptedString);
                    break;

                case EncryptionMethodOptions.RSAXmlKeyFile:
                    RSAXmlKeyFileConfiguration rsaxmlKeyFileConfiguration = RSAXmlKeyFileConfiguration.GetInstance();
                    RSAXmlKeyFileManager       rsaxmlKeyFileEncryption    = new RSAXmlKeyFileManager(rsaxmlKeyFileConfiguration.PublicKeyFile, rsaxmlKeyFileConfiguration.PrivateKeyFile);
                    retVal = rsaxmlKeyFileEncryption.Decrypt(encryptedString);
                    break;
                }
            }

            return(retVal);
        }
Exemple #3
0
 /// <summary>
 /// Gets the instance of the configuration, based on a default section
 /// </summary>
 /// <returns>AESEncryption Configuration</returns>
 public static AESConfiguration GetInstance()
 {
     return(AESConfiguration.GetInstance(DEFAULT_SECTION));
 }