{"version":3,"file":"JSEncrypt.mjs","sources":["../../../../../packages/utils/jsencrypt/JSEncrypt.js"],"sourcesContent":["var _a\nimport { b64tohex, hex2b64 } from './jselib/jsbn/base64'\nimport { JSEncryptRSAKey } from './JSEncryptRSAKey'\nvar version =\n\ttypeof process !== 'undefined'\n\t\t? (_a = process.env) === null || _a === void 0\n\t\t\t? void 0\n\t\t\t: _a.npm_package_version\n\t\t: undefined\n/**\n *\n * @param {Object} [options = {}] - An object to customize JSEncrypt behaviour\n * possible parameters are:\n * - default_key_size        {number}  default: 1024 the key size in bit\n * - default_public_exponent {string}  default: '010001' the hexadecimal representation of the public exponent\n * - log                     {boolean} default: false whether log warn/error or not\n * @constructor\n */\nvar JSEncrypt = /** @class */ (function () {\n\tfunction JSEncrypt(options) {\n\t\tif (options === void 0) {\n\t\t\toptions = {}\n\t\t}\n\t\toptions = options || {}\n\t\tthis.default_key_size = options.default_key_size ? parseInt(options.default_key_size, 10) : 1024\n\t\tthis.default_public_exponent = options.default_public_exponent || '010001' // 65537 default openssl public exponent for rsa key type\n\t\tthis.log = options.log || false\n\t\t// The private and public key.\n\t\tthis.key = null\n\t}\n\t/**\n\t * Method to set the rsa key parameter (one method is enough to set both the public\n\t * and the private key, since the private key contains the public key paramenters)\n\t * Log a warning if logs are enabled\n\t * @param {Object|string} key the pem encoded string or an object (with or without header/footer)\n\t * @public\n\t */\n\tJSEncrypt.prototype.setKey = function (key) {\n\t\tif (this.log && this.key) {\n\t\t\tconsole.warn('A key was already set, overriding existing.')\n\t\t}\n\t\tthis.key = new JSEncryptRSAKey(key)\n\t}\n\t/**\n\t * Proxy method for setKey, for api compatibility\n\t * @see setKey\n\t * @public\n\t */\n\tJSEncrypt.prototype.setPrivateKey = function (privkey) {\n\t\t// Create the key.\n\t\tthis.setKey(privkey)\n\t}\n\t/**\n\t * Proxy method for setKey, for api compatibility\n\t * @see setKey\n\t * @public\n\t */\n\tJSEncrypt.prototype.setPublicKey = function (pubkey) {\n\t\t// Sets the public key.\n\t\tthis.setKey(pubkey)\n\t}\n\t/**\n\t * Proxy method for RSAKey object's decrypt, decrypt the string using the private\n\t * components of the rsa key object. Note that if the object was not set will be created\n\t * on the fly (by the getKey method) using the parameters passed in the JSEncrypt constructor\n\t * @param {string} str base64 encoded crypted string to decrypt\n\t * @return {string} the decrypted string\n\t * @public\n\t */\n\tJSEncrypt.prototype.decrypt = function (str) {\n\t\t// Return the decrypted string.\n\t\ttry {\n\t\t\treturn this.getKey().decrypt(b64tohex(str))\n\t\t} catch (ex) {\n\t\t\treturn false\n\t\t}\n\t}\n\t/**\n\t * Proxy method for RSAKey object's encrypt, encrypt the string using the public\n\t * components of the rsa key object. Note that if the object was not set will be created\n\t * on the fly (by the getKey method) using the parameters passed in the JSEncrypt constructor\n\t * @param {string} str the string to encrypt\n\t * @return {string} the encrypted string encoded in base64\n\t * @public\n\t */\n\tJSEncrypt.prototype.encrypt = function (str) {\n\t\t// Return the encrypted string.\n\t\ttry {\n\t\t\treturn hex2b64(this.getKey().encrypt(str))\n\t\t} catch (ex) {\n\t\t\treturn false\n\t\t}\n\t}\n\t/**\n\t * Proxy method for RSAKey object's sign.\n\t * @param {string} str the string to sign\n\t * @param {function} digestMethod hash method\n\t * @param {string} digestName the name of the hash algorithm\n\t * @return {string} the signature encoded in base64\n\t * @public\n\t */\n\tJSEncrypt.prototype.sign = function (str, digestMethod, digestName) {\n\t\t// return the RSA signature of 'str' in 'hex' format.\n\t\ttry {\n\t\t\treturn hex2b64(this.getKey().sign(str, digestMethod, digestName))\n\t\t} catch (ex) {\n\t\t\treturn false\n\t\t}\n\t}\n\t/**\n\t * Proxy method for RSAKey object's verify.\n\t * @param {string} str the string to verify\n\t * @param {string} signature the signature encoded in base64 to compare the string to\n\t * @param {function} digestMethod hash method\n\t * @return {boolean} whether the data and signature match\n\t * @public\n\t */\n\tJSEncrypt.prototype.verify = function (str, signature, digestMethod) {\n\t\t// Return the decrypted 'digest' of the signature.\n\t\ttry {\n\t\t\treturn this.getKey().verify(str, b64tohex(signature), digestMethod)\n\t\t} catch (ex) {\n\t\t\treturn false\n\t\t}\n\t}\n\t/**\n\t * Getter for the current JSEncryptRSAKey object. If it doesn't exists a new object\n\t * will be created and returned\n\t * @param {callback} [cb] the callback to be called if we want the key to be generated\n\t * in an async fashion\n\t * @returns {JSEncryptRSAKey} the JSEncryptRSAKey object\n\t * @public\n\t */\n\tJSEncrypt.prototype.getKey = function (cb) {\n\t\t// Only create new if it does not exist.\n\t\tif (!this.key) {\n\t\t\t// Get a new private key.\n\t\t\tthis.key = new JSEncryptRSAKey()\n\t\t\tif (cb && {}.toString.call(cb) === '[object Function]') {\n\t\t\t\tthis.key.generateAsync(this.default_key_size, this.default_public_exponent, cb)\n\t\t\t\treturn\n\t\t\t}\n\t\t\t// Generate the key.\n\t\t\tthis.key.generate(this.default_key_size, this.default_public_exponent)\n\t\t}\n\t\treturn this.key\n\t}\n\t/**\n\t * Returns the pem encoded representation of the private key\n\t * If the key doesn't exists a new key will be created\n\t * @returns {string} pem encoded representation of the private key WITH header and footer\n\t * @public\n\t */\n\tJSEncrypt.prototype.getPrivateKey = function () {\n\t\t// Return the private representation of this key.\n\t\treturn this.getKey().getPrivateKey()\n\t}\n\t/**\n\t * Returns the pem encoded representation of the private key\n\t * If the key doesn't exists a new key will be created\n\t * @returns {string} pem encoded representation of the private key WITHOUT header and footer\n\t * @public\n\t */\n\tJSEncrypt.prototype.getPrivateKeyB64 = function () {\n\t\t// Return the private representation of this key.\n\t\treturn this.getKey().getPrivateBaseKeyB64()\n\t}\n\t/**\n\t * Returns the pem encoded representation of the public key\n\t * If the key doesn't exists a new key will be created\n\t * @returns {string} pem encoded representation of the public key WITH header and footer\n\t * @public\n\t */\n\tJSEncrypt.prototype.getPublicKey = function () {\n\t\t// Return the private representation of this key.\n\t\treturn this.getKey().getPublicKey()\n\t}\n\t/**\n\t * Returns the pem encoded representation of the public key\n\t * If the key doesn't exists a new key will be created\n\t * @returns {string} pem encoded representation of the public key WITHOUT header and footer\n\t * @public\n\t */\n\tJSEncrypt.prototype.getPublicKeyB64 = function () {\n\t\t// Return the private representation of this key.\n\t\treturn this.getKey().getPublicBaseKeyB64()\n\t}\n\tJSEncrypt.version = version\n\treturn JSEncrypt\n})()\nexport { JSEncrypt }\n"],"names":["JSEncrypt"],"mappings":";;;AAAA,IAAI,EAAA,CAAA;AAGJ,IAAI,OACH,GAAA,OAAO,OAAY,KAAA,WAAA,GAAA,CACf,EAAK,GAAA,OAAA,CAAQ,GAAS,MAAA,IAAA,IAAQ,EAAO,KAAA,KAAA,CAAA,GACrC,KACA,CAAA,GAAA,EAAA,CAAG,mBACJ,GAAA,KAAA,CAAA,CAAA;AAUA,IAAA,SAAA;AAAA;AAAA,EAA2B,WAAY;AAC1C,IAAA,SAASA,WAAU,OAAS,EAAA;AAC3B,MAAA,IAAI,YAAY,KAAQ,CAAA,EAAA;AACvB,QAAA,OAAA,GAAU,EAAC,CAAA;AAAA,OACZ;AACA,MAAA,OAAA,GAAU,WAAW,EAAC,CAAA;AACtB,MAAA,IAAA,CAAK,mBAAmB,OAAQ,CAAA,gBAAA,GAAmB,SAAS,OAAQ,CAAA,gBAAA,EAAkB,EAAE,CAAI,GAAA,IAAA,CAAA;AAC5F,MAAK,IAAA,CAAA,uBAAA,GAA0B,QAAQ,uBAA2B,IAAA,QAAA,CAAA;AAClE,MAAK,IAAA,CAAA,GAAA,GAAM,QAAQ,GAAO,IAAA,KAAA,CAAA;AAE1B,MAAA,IAAA,CAAK,GAAM,GAAA,IAAA,CAAA;AAAA,KACZ;AAQA,IAAAA,UAAU,CAAA,SAAA,CAAU,MAAS,GAAA,SAAU,GAAK,EAAA;AAC3C,MAAI,IAAA,IAAA,CAAK,GAAO,IAAA,IAAA,CAAK,GAAK,EAAA;AACzB,QAAA,OAAA,CAAQ,KAAK,6CAA6C,CAAA,CAAA;AAAA,OAC3D;AACA,MAAK,IAAA,CAAA,GAAA,GAAM,IAAI,eAAA,CAAgB,GAAG,CAAA,C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