tangshi300/lib/WXBizDataCrypt.js

21 lines
703 B
JavaScript
Raw Permalink Normal View History

2024-12-05 14:56:07 +08:00
var e = require("crypto");
function r(e, r) {
this.appId = e, this.sessionKey = r;
}
r.prototype.decryptData = function(r, t) {
var a = new Buffer(this.sessionKey, "base64");
r = new Buffer(r, "base64"), t = new Buffer(t, "base64");
try {
var s = e.createDecipheriv("aes-128-cbc", a, t);
s.setAutoPadding(!0);
var i = s.update(r, "binary", "utf8");
i += s.final("utf8"), i = JSON.parse(i);
} catch (e) {
e = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(e);
throw new Error("Illegal Buffer");
}
if (i.watermark.appid !== this.appId) throw new Error("Illegal Buffer");
return i;
}, module.exports = r;