const crypto = require('crypto');
const decodePayNotify = async function (resource) {
try {
const AUTH_KEY_LENGTH = 16;
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');
const ciphertext_bytes = Buffer.from(ciphertext, 'base64');
const cipherdata_length = ciphertext_bytes.length - AUTH_KEY_LENGTH;
const cipherdata_bytes = ciphertext_bytes.slice(0, cipherdata_length);
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(),
]);
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'
})
先确认一下自己的V3key给的对不对