我正在尝试将此C#函数复制到NodeJS函数中。
首先是C#函数。
private byte[] Decrypt(byte[] plainText)
{
using (var aes = new AesManaged())
{
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.Zeros;
var decryptor = aes.CreateDecryptor(Key, Key);
var decrypted = decryptor.TransformFinalBlock(plainText, 0, plainText.Length);
return decrypted;
}
}
这是NodeJS函数,我试图将其转换为。
var crypto = require("crypto")
require('./config');
function decrypt(key, data) {
var decipher = crypto.createDecipher('aes-256-ecb', key);
var decrypted = decipher.update(data, "utf8", "utf8");
decipher.setAutoPadding(true);
decrypted += decipher.final('utf8');
return decrypted;
}
decryptedText = decrypt(process.env.password, process.env.encryptedMessage);
console.log("Decrypted Text: ", decryptedText);
NodeJS函数是错误的,有人可以将C#函数转换为NodeJS函数,因为我对此的经验有限,因为我是前端开发人员。
目前我得到的输出是:
Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
at Error (native)
at Decipher.Cipher.final (crypto.js:158:26)
at decrypt (/Users/dave/Tests/sqs-consumer/app3.js:8:31)