我有同样的情况Decrypt Rijndael 256 Block Size with BouncyCastle
所以我从那篇文章中修复了代码,并替换了我的旧代码
public static string Decrypt(string cipherText, string superSecretPassPhrase)
{
if (cipherText == null)
{
throw new ArgumentNullException(nameof(cipherText));
}
// Get the complete stream of bytes that represent:
// [32 bytes of Salt] + [32 bytes of IV] + [n bytes of CipherText]
var cipherTextBytesWithSaltAndIv = Convert.FromBase64String(cipherText);
// Get the saltbytes by extracting the first 32 bytes from the supplied cipherText bytes.
var saltStringBytes = cipherTextBytesWithSaltAndIv.Take(Keysize / 8).ToArray();
// Get the IV bytes …Run Code Online (Sandbox Code Playgroud)