- APIv3解密报错:Error: Unsupported state or unable to au
const crypto = require('crypto'); const decodePayNotify = async function (resource) { try { const AUTH_KEY_LENGTH = 16; // ciphertext = 密文,associated_data = 填充内容, nonce = 位移 const { ciphertext, associated_data, nonce } = resource; // 密钥 const ac = { key: 'qih*********zha' } const key_bytes = Buffer.from(ac.key, 'utf8'); // 位移 const nonce_bytes = Buffer.from(nonce, 'utf8'); // 填充内容 const associated_data_bytes = Buffer.from(associated_data, 'utf8'); // 密文Buffer const ciphertext_bytes = Buffer.from(ciphertext, 'base64'); // 计算减去16位长度 const cipherdata_length = ciphertext_bytes.length - AUTH_KEY_LENGTH; // upodata const cipherdata_bytes = ciphertext_bytes.slice(0, cipherdata_length); // tag const auth_tag_bytes = ciphertext_bytes.slice(cipherdata_length, ciphertext_bytes.length); const decipher = crypto.createDecipheriv( 'aes-256-gcm', ac.key, nonce ); decipher.setAuthTag(auth_tag_bytes); decipher.setAAD(associated_data); const output = Buffer.concat([ decipher.update(cipherdata_bytes), decipher.final(), ]); // 解密后 转成 JSON 格式输出 return JSON.parse(output.toString('utf8')); } catch (error) { console.error('解密错误:', error); return null; } } decodePayNotify({ original_type: 'transaction', algorithm: 'AEAD_AES_256_GCM', ciphertext: 'ajqHZgQzJNJxo7xVF6JZHa2nkIH5a87+I7w6Iag78V4SnmOdKktEe6HNLXmCMe+5L7QEe2jNNK8u+Fja31RxmmmeljEOv25nZKEmBfQHIzgbSiEL4l8cG6w4422J4/pFVd7jec+ZV3IgPaICkuhGICa4I5ZzSBtAAZREZI70+qDminPxN8xJfvPKZOT5JU79ca1HTpT1QY/tHwDJdgObw2HEmQCqvUPpSMaNK7J/EokmqJ8wrKx6Wwc0gouAz02pUp5jvDrBxwN/9/ZlDvMFXJ0FKKmY4btU2y9avsbEDPAc5U67QhJ5ARoVz3dwGMy0xzVNJkkTjyuF1PFWwP5QyQTYYKu3KuNo93T+QjA3BerbCL5Awppa0/jYyRCK5Ps4nA9DA05GrtPdUaS15d42n44bO+Qr9dBpWH2LSvLw4z9q2IRw2K5MckLD6CmjbjI6W30hTFMZAXsvrlYPMzjZepBkbQ+QGIbZIGE0jqQd8NJDLXeNaZ9+Lmvqwca+CJPShbVp4R6D+g+zWx4L5wYFYkT92zyU+65kbCrKx/0pov+mBH/DzpDLduW8yl9GCwfJ73DJP5rVFw==', associated_data: 'transaction', nonce: 'D3vkvUwUqh2f' }) // 解密错误: Error: Unsupported state or unable to authenticate data
01-03 - base64图片在开发工具和手机调试环境可以显示,为什么关闭调试环境不显示?
[图片][图片]
2023-12-26 - IOS直接访问页面微信签名没问题,可是从页面里跳转签名就会报错,报错内容为空?
首先安卓没有问题~ IOS直接通过链接进入人脸识别页面,微信配置接口调用成功,后期的调起人脸识别也没有问题。 可是直接从我们自己的页面跳转到人脸识别页面,微信配置接口报错,err_msg内容为空,导致后面的人脸识别也无法调起。 我看网上说是spa的路由跳转的问题,可是人脸识别功能是我们新做的功能,是在不同域名下的页面啊,就是用location.href跳转的,还是有同样的问题
2021-08-12