官方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 |
求问
同问