0
我試圖讓這個AES示例代碼工作。但是我沒有收到任何返回到我的cipherText變量的東西。我沒有得到錯誤,只是沒有返回。我在這裏做錯了什麼?AES加密器不能正常工作
public byte[] key { get; set; }
public byte[] IV { get; set; }
public byte[] ciphertext { get; set; }
public string plainText { get; set; }
public byte[] Encrypt(string InputPlaintext)
{
InputPlaintext = "attack at dawn";
using (AesCryptoServiceProvider AESEncryptor = new AesCryptoServiceProvider())
{
////using the AesCryptoServiceProvider to generate the IV and Key
key = AESEncryptor.Key;
IV = AESEncryptor.IV;
ICryptoTransform encryptor = AESEncryptor.CreateEncryptor(key, IV);
using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(InputPlaintext);
ciphertext = msEncrypt.ToArray();
return ciphertext;
}
}
}
};
}