UNPKG

strong-cryptor

Version:
49 lines 2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var crypto_1 = __importDefault(require("crypto")); /** * separate the ivString with the encrypted data string * @param encryptedData encrypted data that will be separated * @param encoding the encoding that used in the encryption process * @returns object that contains the ivString and encrypted data string */ function getIvAndEncryptedDataOnly(encryptedData, encoding) { switch (encoding) { case 'base64': return { encryptedDataString: encryptedData.substring(22, encryptedData.length), ivString: encryptedData.substring(0, 22) }; case 'hex': return { encryptedDataString: encryptedData.substring(32, encryptedData.length), ivString: encryptedData.substring(0, 32) }; } } exports.getIvAndEncryptedDataOnly = getIvAndEncryptedDataOnly; /** * remove padding( `=` | equals sign) for string that encoded with base64 * @param encodedString base64 string that the padding will be removed * @returns base64 string that the padding already removed */ function removeBase64Padding(encodedString) { return encodedString.replace(/={1,2}$/, ''); } exports.removeBase64Padding = removeBase64Padding; /** * generate random 256bits(32 characters) key * @returns return a 32 characters string */ function genKey() { return crypto_1.default.randomBytes(16).toString('hex'); } exports.genKey = genKey; function getDeprecateMessage(functionName, oldVersion, newVersion) { return "\u001B[33m " + functionName + "() is deprecated in version " + oldVersion + " and will be deleted in version " + newVersion + ", please use Class Base instead \u001B[0m"; } exports.getDeprecateMessage = getDeprecateMessage; //# sourceMappingURL=utils.js.map