我正在将一个NodeJS应用程序与ColdFusion应用程序合并。在ColdFusion中使用下面的方法进行加密,其中key是加密密钥字符串。
key = 'nQw7y6QejwGFh/SNrul20Q=='
encrypt(value, key, "AES/CBC/PKCS5Padding", "HEX");
接下来,在NodeJS中,我试图使用加密模块进行解密
const crypto = require('crypto');
const key = "nQw7y6QejwGFh/SNrul20Q==";
const binaryEncryptionKey = new Buffer( key, "base64" );
decrypt = (value) => {
try {
var decipher = crypto.createDecipheriv( "AES-128-CBC", binaryEncryptionKey );
var value = (
decipher.update( value, "base64", "utf8" ) +
decipher.final( "utf8" )
);
return value;
} catch (err) {
console.log(err);
}
}
首先它会返回缓冲区的警告:
DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
然后,我遇到了错误:
TypeError [ERR_INVALID_ARG_TYPE]: The "iv" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
我没有"iv",因为ColdFusion端没有使用它进行加密。在NodeJS中解密是否可能?
- 当我改用Buffer.alloc时,出现错误:
TypeError [ERR_INVALID_ARG_TYPE]: The "size" argument must be of type number. Received type string ('nQw7y6QejwGFh/SNrul20Q==..)
例如,我有以下加密字符串:
FB391CAAE5CD8FF47C55211ED8636D213C95F233B615D4E56CB7CD6B051D01DF356E1C45ED7AABAB5F9BCBB9EED6355B
谢谢。