C # Rijndael Расшифровка кода в Node.js с ошибкой плохой расшифровки - PullRequest
0 голосов
/ 17 января 2019

Пытается преобразовать код расшифровки 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);
...