UNPKG

@liuhlightning/wx-pay

Version:
24 lines 908 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decrypto = decrypto; exports.decryptoByPrivateKey = decryptoByPrivateKey; const crypto_1 = require("crypto"); function decrypto(nonce, ciphertext, associatedData) { const d = (0, crypto_1.createDecipheriv)("aes-256-gcm", this.apiv3Key, nonce); const buf = Buffer.from(ciphertext, "base64"); const authTag = buf.subarray(-16); const data = buf.subarray(0, -16); d.setAuthTag(authTag); d.setAAD(Buffer.from(associatedData)); const res = d.update(data, undefined, "utf8"); d.final(); return res; } function decryptoByPrivateKey(ciphertext) { const c = (0, crypto_1.privateDecrypt)({ key: this.privateKey, padding: crypto_1.constants.RSA_PKCS1_OAEP_PADDING, }, Buffer.from(ciphertext, "base64")); return c.toString("utf-8"); } //# sourceMappingURL=decrypto.js.map