AES Decrypt Text with password - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:AES

Description

AES Decrypt Text with password

Demo Code


using System.Security.Cryptography;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//  ww w .  j a va2s  . c  o m

public class Main{
        public static string Decrypt(string text, string password)
        {
            byte[] Buffer = Convert.FromBase64String(text);
            Buffer = Decrypt(Buffer, password);
            return UTF8Encoding.UTF8.GetString(Buffer);
        }
        public static byte[] Decrypt(byte[] bytes, string password)
        {
            AesManaged AES = new AesManaged();

            AES.Key = ProcessKey(password);
            AES.Mode = CipherMode.ECB;

            ICryptoTransform AESDecrypt = AES.CreateDecryptor();
            return AESDecrypt.TransformFinalBlock(bytes, 0, bytes.Length);
        }
}

Related Tutorials