Decrypt AES - CSharp Security

CSharp examples for Security:Cryptography

Description

Decrypt AES

Demo Code


using System.Web.UI.WebControls;
using System.Web;
using System.Text.RegularExpressions;
using System.Text;
using System.Security.Cryptography;
using System.IO.Compression;
using System.IO;//from w  ww .java  2s  .  com
using System.Diagnostics;
using System.Collections.Generic;
using System;

public class Main{
        public static String DecryptAES(String str, string aeskey)
        {
            Byte[] keyArray = System.Text.UTF8Encoding.UTF8.GetBytes(aeskey);
            Byte[] toEncryptArray = Convert.FromBase64String(str);

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

            System.Security.Cryptography.ICryptoTransform cTransform = rDel.CreateDecryptor();
            Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

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

Related Tutorials