using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace ET
{
public static class LogSplicingUtil
{
///
/// AES加密算法
///
/// 明文字符串
/// 密钥
/// 返回加密后的密文字节数组
public static string AESEncrypt(string plainText, string strKey)
{
//分组加密算法
SymmetricAlgorithm des = Aes.Create();
byte[] inputByteArray = Encoding.UTF8.GetBytes(plainText); //得到需要加密的字节数组
//设置密钥及密钥向量
byte[] key1 =
{
0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB,
0xCD, 0xEF
};
des.Key = Encoding.UTF8.GetBytes(strKey);
des.IV = key1;
MemoryStream ms = new MemoryStream();
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 Convert.ToBase64String(cipherBytes);
}
}
}