fca-nazrul-remastered
Version:
Facebook-chat-api protect and deploy by Kanzu and HZI Team
23 lines (19 loc) • 836 B
JavaScript
;
const crypto = require('crypto');
const aes = require("aes-js");
module.exports.encryptState = function encryptState(data, key) {
let hashEngine = crypto.createHash("sha256");
let hashKey = hashEngine.update(key).digest();
let bytes = aes.utils.utf8.toBytes(data);
let aesCtr = new aes.ModeOfOperation.ctr(hashKey);
let encryptedData = aesCtr.encrypt(bytes);
return aes.utils.hex.fromBytes(encryptedData);
};
module.exports.decryptState = function decryptState(data, key) {
let hashEngine = crypto.createHash("sha256");
let hashKey = hashEngine.update(key).digest();
let encryptedBytes = aes.utils.hex.toBytes(data);
let aesCtr = new aes.ModeOfOperation.ctr(hashKey);
let decryptedData = aesCtr.decrypt(encryptedBytes);
return aes.utils.utf8.fromBytes(decryptedData);
};