Aes Decryptor - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:AES

Description

Aes Decryptor

Demo Code


using System.Text;
using System.Security.Cryptography;
using System;/*ww  w  . ja va  2  s  .  c  om*/

public class Main{
        public static string AesDecryptor(byte[] bsFile, string password)
        {
            RijndaelManaged aes = new RijndaelManaged();
            string MD5Pwd = MD5Encrypt(password);
            aes.Key = Encoding.UTF8.GetBytes(MD5Pwd);
            aes.IV = Encoding.UTF8.GetBytes(MD5Pwd.Substring(8, 16));
            aes.Mode = CipherMode.CBC;
            aes.Padding = PaddingMode.PKCS7;

            ICryptoTransform transform = aes.CreateDecryptor();
            var deBytes = transform.TransformFinalBlock(bsFile, 0, bsFile.Length);
            return Encoding.UTF8.GetString(deBytes);
        }
}

Related Tutorials