Decrypt with RijndaelManaged - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:Encrypt Decrypt

Description

Decrypt with RijndaelManaged

Demo Code


using System.Text;
using System.Security.Cryptography;
using System;/*from   w w  w .  ja  v  a2s  .  co  m*/

public class Main{
        public static string Decrypt(string toDecrypt, string key)
        {
            byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);
            byte[] toEncryptArray = Convert.FromBase64String(toDecrypt);

            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.Mode = CipherMode.ECB;
            rDel.Padding = PaddingMode.PKCS7;

            ICryptoTransform cTransform = rDel.CreateDecryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

            return UTF8Encoding.UTF8.GetString(resultArray);
        }
}

Related Tutorials