"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.generateMd5=generateMd5,exports.checkBufferSignature=checkBufferSignature,exports.checkSignature=checkSignature,exports.checkFileMd5Signature=checkFileMd5Signature,exports.aesEncrypt=aesEncrypt,exports.aesDecrypt=aesDecrypt;const fs=require("fs"),crypto=require("crypto"),PUBLIKEY="-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZm2cFP/uF81V5KH/B9dn/g7WA\nCM3yu0P7n9sm/O6c58HTYI0+xugCfwMuoX7hyU4jkWbZ/BYK7IgWhmVfiRtgomJe\nwuZlxfGUpmrr1PA2KbYVpPW0V6e/2uZu1Ev3xU7PkHKYf4AKgPO8w98hvKlUJRbk\nH4AYMxX6eL9j9qCBGQIDAQAB\n-----END PUBLIC KEY-----";function generateMd5(e){const r=crypto.createHash("md5");r.update(e);return r.digest("hex")}function checkBufferSignature(e,r,t){if(!r)return!1;return checkSignature(generateMd5(e),r,t)}function checkSignature(e,r,t){if(!r)return!1;const n=Buffer.from(r,"base64"),c=crypto.createVerify("RSA-SHA1");return c.update(e),!!c.verify(t||PUBLIKEY,n)}function checkFileMd5Signature(e,r,t){return checkBufferSignature(fs.readFileSync(e),r,t)}function aesEncrypt(e){const{data:r,key:t,iv:n,algorithm:c}=e,u=crypto.createCipheriv(c||"aes-128-cbc",t,n);let a=u.update(r,"utf8","binary");return a+=u.final("binary"),a=Buffer.from(a,"binary").toString("base64"),a}function aesDecrypt(e){const{key:r,iv:t,algorithm:n}=e,c=Buffer.from(e.data,"base64").toString("binary"),u=crypto.createDecipheriv(n||"aes-128-cbc",r,t);let a=u.update(c,"binary","utf8");return a+=u.final("utf8"),a}