UNPKG

@iredium/butterfly

Version:
29 lines (28 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var crypto = require("crypto"); var DEFAULT_ALGORITHM = 'aes-256-ctr'; var Crypto = /** @class */ (function () { function Crypto() { } Crypto.encrypt = function (text, outputEncoding, algorithm) { if (outputEncoding === void 0) { outputEncoding = 'hex'; } if (algorithm === void 0) { algorithm = DEFAULT_ALGORITHM; } var cryptoPassword = process.env.IREDIUM_CRYPTO_PASSWORD || ''; var cipher = crypto.createCipher(algorithm, cryptoPassword); var crypted = cipher.update(text, 'utf8', outputEncoding); crypted += cipher.final(outputEncoding); return crypted; }; Crypto.decrypt = function (text, inputEncoding, algorithm) { if (inputEncoding === void 0) { inputEncoding = 'hex'; } if (algorithm === void 0) { algorithm = DEFAULT_ALGORITHM; } var cryptoPassword = process.env.IREDIUM_CRYPTO_PASSWORD || ''; var decipher = crypto.createDecipher(algorithm, cryptoPassword); var dec = decipher.update(text, inputEncoding, 'utf8'); dec += decipher.final('utf8'); return dec; }; return Crypto; }()); exports.Crypto = Crypto;