解密encryptedData 出现Illegal Buffer
官方nodejs解密这段代码, 有一定的概率出现throw new Error('Illegal Buffer') 请问是什么原因,查了很久参数传送没问题。求官方给我回复,在线等,因为上线前遇到这个奇怪问题,见到论坛都有类似的问题 都没有解决的。!!!!!! 相关介绍:https://mp.weixin.qq.com/debug/wxadoc/dev/api/signature.html 提供相关的真实数据方便官方帮忙查找下原因是什么: [代码]var[代码] [代码]appId = [代码][代码]"wxb52dabb4ae6c5e5f"[代码][代码];[代码][代码]var[代码] [代码]sessionKey = [代码][代码]"Av/kbm77la18Bo+vDfg9Hw==";[代码][代码]var[代码] [代码]encryptedData = [代码][代码]"wtv8PmAjj/ht48phniECl6DlLjar8OuIC9ghKH6yyNmo6FzHQIKc4/Rf3BkvHdWgT62ogUvxjMkmVFUvOpkKpFMYZ5YFk6Nd3MghV8kdrWLuf5XnoqGLkFhI+LVTkhlbeGF3UQZCIn4N0wfnvbjnWTrdiUaqJRyMz7vh0xggRPL3PHcaIb5oyYrV349xsb4gyzeKPpTRC9ED3o4Yf+SPLExfdiTBnaZ1OaYsdqsVirgh60Z7OxTmXVUAsedbSJZ4z4+nJvbkE/63Twb/a8+64ByPhojwMSsqJru5mLFFIZ+LEf250K+sqfbMhvWnmAYdQLy0ZcSKKqXzFZMmZGa56V5IdRQc8jo4gYVzrhuxbynQghQcjpRYDLDdUUWn5alAg8ruQ6D7uM1qygGbluASixUR59w59UP2QGplgDOXCazC90NB/0ZokvrATObKXpixiUgMu+azL9pEUgCoi1mxaMp47mpl5zyGCAuDoG/54cQ="[代码][代码];[代码][代码]var[代码] [代码]iv = [代码][代码]"7vXKt43CYsQwntPHIImz0Q=="[代码][代码];[代码] ================================= [代码]var[代码] [代码]crypto = require([代码][代码]'crypto'[代码][代码])[代码][代码]function[代码] [代码]WXBizDataCrypt(appId, sessionKey) {[代码][代码] [代码][代码]this[代码][代码].appId = appId[代码][代码] [代码][代码]this[代码][代码].sessionKey = sessionKey[代码][代码]}[代码][代码]WXBizDataCrypt.prototype.decryptData = [代码][代码]function[代码] [代码](encryptedData, iv) {[代码][代码] [代码][代码]// base64 decode[代码][代码] [代码][代码]var[代码] [代码]sessionKey = [代码][代码]new[代码] [代码]Buffer([代码][代码]this[代码][代码].sessionKey, [代码][代码]'base64'[代码][代码])[代码][代码] [代码][代码]encryptedData = [代码][代码]new[代码] [代码]Buffer(encryptedData, [代码][代码]'base64'[代码][代码])[代码][代码] [代码][代码]iv = [代码][代码]new[代码] [代码]Buffer(iv, [代码][代码]'base64'[代码][代码])[代码][代码] [代码][代码]try[代码] [代码]{[代码][代码] [代码][代码]// 解密[代码][代码] [代码][代码]var[代码] [代码]decipher = crypto.createDecipheriv([代码][代码]'aes-128-cbc'[代码][代码], sessionKey, iv)[代码][代码] [代码][代码]// 设置自动 padding 为 true,删除填充补位[代码][代码] [代码][代码]decipher.setAutoPadding([代码][代码]true[代码][代码])[代码][代码] [代码][代码]var[代码] [代码]decoded = decipher.update(encryptedData, [代码][代码]'binary'[代码][代码], [代码][代码]'utf8'[代码][代码])[代码][代码] [代码][代码]decoded += decipher.final([代码][代码]'utf8'[代码][代码])[代码][代码] [代码][代码]decoded = JSON.parse(decoded)[代码][代码] [代码][代码]} [代码][代码]catch[代码] [代码](err) {[代码][代码] [代码][代码]throw[代码] [代码]new[代码] [代码]Error([代码][代码]'Illegal Buffer'[代码][代码])[代码][代码] [代码][代码]}[代码][代码] [代码][代码]if[代码] [代码](decoded.watermark.appid !== [代码][代码]this[代码][代码].appId) {[代码][代码] [代码][代码]throw[代码] [代码]new[代码] [代码]Error([代码][代码]'Illegal Buffer'[代码][代码])[代码][代码] [代码][代码]}[代码][代码] [代码][代码]return[代码] [代码]decoded[代码][代码]}[代码][代码]module.exports = WXBizDataCrypt[代码]