/// AES加密 /// </summary> /// <param name="inputdata">输入的数据</param> /// <param name="iv">向量128位</param> /// <param name="strKey">加密密钥</param> /// <returns></returns> public static byte[] AESEncrypt(byte[] inputdata, byte[] iv, string strKey) { //分组加密算法 SymmetricAlgorithm des = Rijndael.Create(); byte[] inputByteArray = inputdata;//得到需要加密的字节数组 //设置密钥及密钥向量 des.Key = Encoding.UTF8.GetBytes(strKey.Substring(0, 32)); des.IV = iv; using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write)) { cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); byte[] cipherBytes = ms.ToArray();//得到加密后的字节数组 cs.Close(); ms.Close(); return cipherBytes; } } } /// <summary> /// AES解密 /// </summary> /// <param name="inputdata">输入的数据</param> /// <param name="iv">向量128</param> /// <param name="strKey">key</param> /// <returns></returns> public static byte[] AESDecrypt(byte[] inputdata, byte[] iv, string strKey) { SymmetricAlgorithm des = Rijndael.Create(); des.Key = Encoding.UTF8.GetBytes(strKey.Substring(0, 32)); des.IV = iv; byte[] decryptBytes = new byte[inputdata.Length]; using (MemoryStream ms = new MemoryStream(inputdata)) { using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Read)) { cs.Read(decryptBytes, 0, decryptBytes.Length); cs.Close(); ms.Close(); } } return decryptBytes; }
下载说明
☉本站所有源码和资源均由站长亲自测试-绝对保证都可以架设,运营!
☉如源码和资源有损坏或所有链接均不能下载,请告知管理员,
☉本站软件和源码大部分为站长独资,资源购买和收集,放心下载!
☉唯一站长QQ:1004003180 [人格担保-本站注重诚信!]
☉购买建议E-mail:1004003180@qq.com 源码收购 E-mail:1004003180@qq.com
☉本站文件解压密码 【文章内都自带解压密码,每个密码不同!】