Example #1
0
        /// <summary>
        /// Decrypts a string
        /// </summary>
        /// <param name="encryptedData">Encrypted data</param>
        /// <returns>Decrypted string</returns>
        public string Decrypt(string encryptedData)
        {
            string retVal = string.Empty;

            if (this.CertificateFile != null)
            {
                RSAEncryptionHelper certificateHelper = new RSAEncryptionHelper(2048);
                retVal = certificateHelper.Decrypt(encryptedData, false, this.CertificateFile);
            }

            return(retVal);
        }
Example #2
0
        /// <summary>
        /// Decrypt a give string
        /// </summary>
        /// <param name="encryptedString">The original encrypted string</param>
        /// <returns>The decrytped string</returns>
        public string Decrypt(string encryptedString)
        {
            string retVal = string.Empty;

            if (!string.IsNullOrEmpty(encryptedString))
            {
                using (var p = RSAEncryptionHelper.FromXmlString(this.GetKeyFileContents(this.PrivateKeyFile)))
                {
                    retVal = Encoding.UTF8.GetString(p.Decrypt(Convert.FromBase64String(encryptedString), null));
                }
            }

            return(retVal);
        }
Example #3
0
        /// <summary>
        /// Encrypt a give string
        /// </summary>
        /// <param name="decryptedString">The original decrypted string</param>
        /// <returns>The encrypted string</returns>
        public string Encrypt(string decryptedString)
        {
            string retVal = string.Empty;

            if (!string.IsNullOrEmpty(decryptedString))
            {
                using (var p = RSAEncryptionHelper.FromXmlString(this.GetKeyFileContents(this.PrivateKeyFile)))
                {
                    byte[] encryptedBytes = p.Encrypt(System.Text.Encoding.UTF8.GetBytes(decryptedString), null);
                    retVal = Convert.ToBase64String(encryptedBytes);
                }
            }

            return(retVal);
        }
Example #4
0
        /// <summary>
        /// Decrypt given a byte array, padding and a certificate
        /// </summary>
        /// <param name="encryptedData">Encrypted byte array</param>
        /// <param name="useOAEP">Use OAEP Padding</param>
        /// <param name="certificate">Encryption Certificate</param>
        /// <returns>Decrypted byte array</returns>
        public byte[] Decrypt(byte[] encryptedData, bool useOAEP, X509Certificate2 certificate)
        {
            if (encryptedData == null)
            {
                throw new ArgumentNullException("encryptedData");
            }

            if (certificate == null)
            {
                throw new ArgumentNullException("certificate");
            }

            using (RSA provider = RSAEncryptionHelper.FromXmlString(this.GetXmlKeyPair(certificate)))
            {
                return(provider.Decrypt(encryptedData, null));// useOAEP);
            }
        }
Example #5
0
        /// <summary>
        /// Encrypt some plaintext byte array using padding
        /// </summary>
        /// <param name="plainData">Plaintext byte array</param>
        /// <param name="useOAEP">Use OAEP Padding</param>
        /// <param name="certificate">Encryption Certificate</param>
        /// <returns>encrypted byte array</returns>
        public byte[] Encrypt(byte[] plainData, bool useOAEP, X509Certificate2 certificate)
        {
            if (plainData == null)
            {
                throw new ArgumentNullException("plainData");
            }

            if (certificate == null)
            {
                throw new ArgumentNullException("certificate");
            }

            using (RSA provider = RSAEncryptionHelper.FromXmlString(this.GetPublicKey(certificate)))
            {
                return(provider.Encrypt(plainData, null));// useOAEP);
            }
        }