我们有一个用于加密的辅助类,老实说,它可能是多年前从 Stack Overflow 复制的。
目前,我们正尝试将部分代码移植到 .NET Core,但我们发现它不起作用,因为 .NET Core 实现RijndaelManaged不支持 256 块大小。从我读到的内容来看,BouncyCastle 似乎仍然应该支持它,但我无法让它工作。“未加密”的文本只是一堆乱码。我确定我做错了什么,但对于我的生活,我无法弄清楚这一点。
这是该类的原始 .Net Framework 版本:
internal static class StringEncryptor
{
private const int Keysize = 256;
private const int _iterations = 1000;
private const int _hashLenth = 20;
public static string Encrypt(string plainText, string superSecretPassPhrase)
{
// Salt and IV is randomly generated each time, but is preprended to encrypted cipher text
// so that the same Salt and IV values can be used when decrypting. …Run Code Online (Sandbox Code Playgroud)