美文网首页
node 微信支付证书APIv3解密

node 微信支付证书APIv3解密

作者: 吴占超 | 来源:发表于2019-10-28 10:40 被阅读0次

鉴于微信海外支付的apiv3解密没有node-sdk所以整理如下:

const crypto = require('crypto');

/**
 * 解密
 *
 * @param {string} cipherText 文本
 * @param {string} key 平台密钥
 * @param {string} iv 偏移量(nonce)
 * @param {string} add associated_data
 * @returns { id: '4200000421201910275143005680',appid: 'wx459f9b30b8d5b725',mchid: '105242849',out_trade_no: '1572159737154',payer: { openid: 'oDBryjphoxK-jG0UWcqEu4dCavZI' },amount:{ total: 10,currency: 'HKD',payer_total: 9,payer_currency: 'CNY',exchange_rate: { type: 'SETTLEMENT_RATE', rate: 100000000 } },trade_type: 'JSAPI',trade_state: 'SUCCESS',trade_state_desc: '支付成功',bank_type: 'CFT',success_time: '2019-10-27T15:02:26+08:00' }
 */
function test(cipherText, key, iv, add) {
  cipherText = Buffer.from(cipherText, 'base64');
  let authTag = cipherText.slice(cipherText.length - 16);
  let data = cipherText.slice(0, cipherText.length - 16);
  let decipher = crypto.createDecipheriv('aes-256-gcm', key, iv);
  decipher.setAuthTag(authTag);
  decipher.setAAD(Buffer.from(add));
  let decoded = decipher.update(data, null, 'utf8');
  decipher.final();
  return JSON.parse(decoded);
}

相关文章

网友评论

      本文标题:node 微信支付证书APIv3解密

      本文链接:https://www.haomeiwen.com/subject/owbvvctx.html