UNPKG

vulcain-corejs

Version:
26 lines (24 loc) 1.01 kB
"use strict"; const system_1 = require("./system"); const crypto = require("crypto"); const conventions_1 = require("../../utils/conventions"); class CryptoHelper { constructor() { this.secretKey = system_1.System.createSharedConfigurationProperty(conventions_1.Conventions.instance.VULCAIN_SECRET_KEY, conventions_1.Conventions.instance.defaultSecretKey); } encrypt(value) { let cipher = crypto.createCipher('aes-256-ctr', this.secretKey.value); let encrypted = cipher.update(value, 'utf8', 'binary'); encrypted += cipher.final('binary'); let hexVal = new Buffer(encrypted, 'binary'); return hexVal.toString('base64'); } decrypt(value) { let decipher = crypto.createDecipher('aes-256-ctr', this.secretKey.value); let decrypted = decipher.update(value, 'base64', 'utf8'); decrypted += decipher.final('utf8'); return decrypted; } } exports.CryptoHelper = CryptoHelper; //# sourceMappingURL=crypto.js.map