UNPKG

lss-mqtt

Version:

LSS-MQTT framework in NodeJS implementation"

24 lines 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const crypto_1 = require("crypto"); class Coder { constructor(password, textCoding = 'ascii', cipherCoding = 'hex') { this.password = password; this.textCoding = textCoding; this.cipherCoding = cipherCoding; this.algorithm = 'chacha20-poly1305'; this.iv = Buffer.alloc(12, 0); this.cipher = crypto_1.createCipheriv(this.algorithm, this.password, this.iv, { authTagLength: 16 }); this.decipher = crypto_1.createDecipheriv(this.algorithm, this.password, this.iv, { authTagLength: 16 }); } encode(data) { this.cipher = crypto_1.createCipheriv(this.algorithm, this.password, this.iv, { authTagLength: 16 }); return this.cipher.update(data, this.textCoding, this.cipherCoding); } decode(cipher) { this.decipher = crypto_1.createDecipheriv(this.algorithm, this.password, this.iv, { authTagLength: 16 }); return this.decipher.update(cipher, this.cipherCoding, this.textCoding); } } exports.Coder = Coder; //# sourceMappingURL=coder.js.map