我是新手,AES 加密模块不是我制作的,所以我有点挣扎。
我可以分享的事情:
private static string DecryptAES(byte[] key, string encryptedString)
{
// Initialise
AesManaged decryptor = new AesManaged();
byte[] encryptedData = Convert.FromBase64String(encryptedString);
// Set the key
decryptor.Key = key; // We have this value
decryptor.IV = key; // We have this value
// create a memory stream
using MemoryStream decryptionStream = new MemoryStream();
// Create the crypto stream
using (CryptoStream decrypt = new CryptoStream(decryptionStream, decryptor.CreateDecryptor(), CryptoStreamMode.Write))
{
decrypt.Write(encryptedData, 0, encryptedData.Length);
decrypt.FlushFinalBlock();
}
// Return the unencrypted data
byte[] decryptedData = decryptionStream.ToArray();
return Encoding.UTF8.GetString(decryptedData, 0, decryptedData.Length);
}
我应该如何处理这个问题?我对我的电脑和服务器之间的 dll 文件感到怀疑,也许 System.Security.Cryptography 不一样?我将该 dll 复制到 API 文件夹,但什么也没做。
我不知道抛出了什么异常,您可以澄清问题以更好地描述发生的情况。
同时,Microsoft 展示了这个作为示例。也许当他们这样做时写入流。我假设您的异常是在 FlushFinalBlock 方法中抛出的。
// Create a decryptor to perform the stream transform. ICryptoTransform decryptor = rijAlg.CreateDecryptor(rijAlg.Key, rijAlg.IV); // Create the streams used for decryption. using (MemoryStream msDecrypt = new MemoryStream(cipherText)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { using (StreamReader srDecrypt = new StreamReader(csDecrypt)) { // Read the decrypted bytes from the decrypting stream // and place them in a string. plaintext = srDecrypt.ReadToEnd(); } } }