Aes Encryptor - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:AES

Description

Aes Encryptor

Demo Code


using System.Text;
using System.Security.Cryptography;
using System;//from  w w w  .j a  va  2  s.c  o m

public class Main{
        public static byte[] AesEncryptor(string input, string password)
        {
            byte[] bsFile = System.Text.Encoding.UTF8.GetBytes(input);
            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.CreateEncryptor();
            return transform.TransformFinalBlock(bsFile, 0, bsFile.Length);
        }
}

Related Tutorials