[C#]AES
說明
http://zh.wikipedia.org/zh-hant/%E8%B3%87%E6%96%99%E5%8A%A0%E5%AF%86%E6%A8%99%E6%BA%96
http://www.baike.com/wiki/AES%E5%8A%A0%E5%AF%86%E7%AE%97%E6%B3%95
AES程式碼
[WebMethod]
public String AESEncrypt(String plainText, String AESKey)
{
byte[] binputString = Encoding.Default.GetBytes(plainText);
RijndaelManaged aes = new RijndaelManaged();
aes.KeySize = 128;
aes.Key = System.Text.UTF8Encoding.UTF8.GetBytes(AESKey);
// aes.Key = convertHexToByte(AESKey);
aes.BlockSize = 128;
// aes.IV = new byte[16];
ICryptoTransform encryptor = aes.CreateEncryptor();
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write);
cryptoStream.Write(binputString, 0, binputString.Length);
cryptoStream.FlushFinalBlock();
cryptoStream.Close();
byte[] encryptBytes = memoryStream.ToArray();
string encryptedData = Convert.ToBase64String(encryptBytes);
return encryptedData;
}
參考:http://www.dotblogs.com.tw/yc421206/archive/2012/04/18/71609.aspx
留言