/// <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 the instance of the configuration, based on a default section /// </summary> /// <returns>AESEncryption Configuration</returns> public static AESConfiguration GetInstance() { return(AESConfiguration.GetInstance(DEFAULT_SECTION)); }