Beispiel #1
0
        public string DecryptString(string encryptedString, string decryptionKey, string decryptionSalt)
        {
            string retVal = string.Empty;

            if (!string.IsNullOrEmpty(encryptedString))
            {
                AESManager internalManager = new AESManager(decryptionKey, decryptionSalt);
                retVal = internalManager.Decrypt(encryptedString);
            }

            return(retVal);
        }
Beispiel #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);
        }