/// <summary>
        /// Gets an instance of the key store encryption configuration using a specified configuration section
        /// </summary>
        /// <param name="configurationSection">Configuration Section</param>
        /// <returns>Key Store Encryption Configuration</returns>
        public static KeyStoreConfiguration GetInstance(string configurationSection)
        {
            if (configurationInstance == null)
            {
                configurationInstance = (KeyStoreConfiguration)System.Configuration.ConfigurationManager.GetSection(configurationSection);
            }

            return(configurationInstance);
        }
Exemple #2
0
        /// <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);
        }
 /// <summary>
 /// Gets an instance of the key store encryption configuration using the default section
 /// </summary>
 /// <returns>Key Store Encryption Configuration</returns>
 public static KeyStoreConfiguration GetInstance()
 {
     return(KeyStoreConfiguration.GetInstance(DEFAULT_SECTION));
 }