尝试将C#Rijndael解密代码转换为Node.js,但收到错误不良解密
用于解密的C#代码:
RijndaelManaged RMCrypto = new RijndaelManaged();
byte[] data = Convert.FromBase64String(strCript.Replace(" ", "+"));
byte[] initVectorBytes;
initVectorBytes = Encoding.ASCII.GetBytes("@1***********H8");
byte[] saltValueBytes;
saltValueBytes = Encoding.ASCII.GetBytes("i**************ng");
PasswordDeriveBytes password;
password = new PasswordDeriveBytes("KEY**************KEY", saltValueBytes, "SHA1", 1);
byte[] keyBytes;
keyBytes = password.GetBytes(256 / 8);
byte[] Key = keyBytes;
byte[] IV = initVectorBytes;
MemoryStream msDncrypt = new MemoryStream(data);
CryptoStream CryptStream = new CryptoStream(msDncrypt, RMCrypto.CreateDecryptor(Key, IV), CryptoStreamMode.Read);
byte[] fromEncrypt = new byte[data.Length];
int len = CryptStream.Read(fromEncrypt, 0, fromEncrypt.Length);
byte[] decrypted = new byte[len];
Array.Copy(fromEncrypt, decrypted, len);
return Encoding.UTF8.GetString(decrypted); //(decrypted,0,decrypted.Length);
用于解密的Node.js代码:
const crypto = require("crypto");
let passkey= "KEY*********KEY";
let salt = "i****************ng"
let d = "u***************=";
d = Buffer.from(d,"base64");
salt = Buffer.from(salt);
const derivedKey = crypto.pbkdf2Sync(passkey,salt, 1000, 32, "sha1");
let iv = Buffer.from("@1B2c3D4e5F6g7H8");
const decipher = crypto.createDecipheriv("aes-256-cbc", derivedKey, iv);
let buf = Buffer.concat([decipher.update(d), decipher.final()]);
let decrypted = buf.toString("utf8");
console.log(decrypted);