예제 #1
0
        /// <summary>
        /// Gets a key file encryption configuration using a specified configuration section
        /// </summary>
        /// <param name="configurationSection">The Configuration Section</param>
        /// <returns>Key File Encryption Configuration</returns>
        public static KeyFileConfiguration GetInstance(string configurationSection)
        {
            if (configurationInstance == null)
            {
                configurationInstance = (KeyFileConfiguration)System.Configuration.ConfigurationManager.GetSection(configurationSection);
            }

            return(configurationInstance);
        }
예제 #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);
        }
예제 #3
0
 /// <summary>
 /// Gets a Key File encryption configuration using the default section
 /// </summary>
 /// <returns>Key File Encryption Configuration</returns>
 public static KeyFileConfiguration GetInstance()
 {
     return(KeyFileConfiguration.GetInstance(DEFAULT_SECTION));
 }