我正在尝试使用此功能进行解密,但我不确定是什么导致它失败
public string Decrypt(byte[] cipherText, byte[] IV, byte[] key)
{
using (AesCryptoServiceProvider AESDecrypt = new AesCryptoServiceProvider())
{
//here we set the key and IV instead having the class generate them.
AESDecrypt.IV = IV;
AESDecrypt.Key = key;
ICryptoTransform decryptor = AESDecrypt.CreateDecryptor(AESDecrypt.Key,
AESDecrypt.IV);
using (MemoryStream msDecrypt = new MemoryStream(cipherText))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt,
decryptor, CryptoStreamMode.Read))
{
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
{
csDecrypt.Flush();
plainText = srDecrypt.ReadToEnd();
return plainText;
}
}
}
}
}
纯文本返回一个空字符串。密钥和 IV 是系统在以前的函数中生成的,并且正在正确传递。