首页 > 代码库 > AES-256加密解密
AES-256加密解密
/// <summary> /// AES-256加密 /// </summary> /// <param name="toEncrypt"></param> /// <returns></returns> public string Encrypt(string toEncrypt) { // 256-AES key byte[] keyArray = UTF8Encoding.UTF8.GetBytes("12345678901234567890123456789012"); byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt); RijndaelManaged rDel = new RijndaelManaged(); rDel.Key = keyArray; rDel.Mode = CipherMode.ECB; rDel.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = rDel.CreateEncryptor(); byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return Convert.ToBase64String(resultArray, 0, resultArray.Length); } /// <summary> /// 解密 /// </summary> /// <param name="toDecrypt">要解密的数据</param> /// <returns>解密好的数据</returns> public string Decrypt(string toDecrypt) { // 256-AES key byte[] keyArray = UTF8Encoding.UTF8.GetBytes("12345678901234567890123456789012"); byte[] toEncryptArray = Convert.FromBase64String(toDecrypt); RijndaelManaged rDel = new RijndaelManaged(); rDel.Key = keyArray; rDel.Mode = CipherMode.ECB; rDel.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = rDel.CreateDecryptor(); byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return UTF8Encoding.UTF8.GetString(resultArray); }
AES-256加密解密
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。