C# AES 加密与解密

/// <summary> ///AES 算法加密(ECB模式) 将明文加密,加密后进行Hex编码,返回密文 /// </summary> /// <param>明文</param> /// <param>密钥</param> /// <returns>加密后Hex编码的密文</returns> public static string AesEncryptor_Hex(string str, string key) { if (string.IsNullOrEmpty(str)) return null; Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str); System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged { Key = StrToHexByte(key), Mode = System.Security.Cryptography.CipherMode.ECB, Padding = System.Security.Cryptography.PaddingMode.PKCS7 }; System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor(); Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return ToHexString(resultArray); }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/8bf632a75d6ab57ec4c3807c9cfdb898.html