标签:aes code array pre key ret style div stat
private static string key { get { return "lelelelelelelele"; } } private static byte[] AesIv = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; public static string AesEncrpt(string input) { Aes aes = Aes.Create(); aes.Key = Encoding.UTF8.GetBytes(key); aes.IV = AesIv; byte[] inputing = Encoding.UTF8.GetBytes(string.IsNullOrEmpty(input) ? string.Empty : input); byte[] reslut = null; using (MemoryStream ms=new MemoryStream ()) { using (CryptoStream cs=new CryptoStream (ms,aes.CreateEncryptor(),CryptoStreamMode.Write)) { cs.Write(inputing,0,inputing.Length); cs.FlushFinalBlock(); reslut = ms.ToArray(); cs.Close(); ms.Close(); } } string a= System.Convert.ToBase64String(reslut); return System.Convert.ToBase64String(reslut); } public static string AesDecrpt(string deinput) { byte[] entypeintpt = System.Convert.FromBase64String(string.IsNullOrEmpty(deinput) ? string.Empty : deinput); Aes aes = Aes.Create(); aes.Key = Encoding.UTF8.GetBytes(key); aes.IV = AesIv; byte[] deinput1 = new byte[entypeintpt.Length]; using (MemoryStream ms=new MemoryStream (entypeintpt)) { using (CryptoStream cs=new CryptoStream (ms,aes.CreateDecryptor(),CryptoStreamMode.Read)) { cs.Read(deinput1, 0, deinput1.Length); cs.Close(); ms.Close(); } } return Encoding.UTF8.GetString(deinput1).Replace("\0", ""); }
标签:aes code array pre key ret style div stat
原文地址:http://www.cnblogs.com/DaJia/p/7725039.html