using System.Security.Cryptography;
public static void Main()
Console.WriteLine(encypt_Aes("testName", "1234"));
public static string encypt_Aes(string username, string password)
string encrypted = string.Empty;
byte[] clearBytes = Encoding.UTF8.GetBytes(password);
using (Aes aesAlg = Aes.Create())
byte[] bytes = Encoding.UTF8.GetBytes(username);
k = SHA256.Create().ComputeHash(bytes);
iv = MD5.Create().ComputeHash(bytes);
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msEncrypt = new MemoryStream())
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
csEncrypt.Write(clearBytes, 0, clearBytes.Length);
encrypted = Convert.ToBase64String(msEncrypt.ToArray());