@a11ywatch/core
Version:
a11ywatch central API
44 lines • 1.32 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.decipher = exports.cipher = void 0;
const crypto_1 = require("crypto");
const config_1 = require("../../config/config");
let key = null;
try {
key = (0, crypto_1.createHash)("sha256").update(config_1.SERVER_SALT, "ascii").digest();
}
catch (e) {
console.error(e);
}
const iv = "1234567890123456";
const cipher = (secret) => {
if (!secret) {
return "";
}
try {
const cipherer = (0, crypto_1.createCipheriv)("aes-256-cbc", key, iv);
const encrypted = cipherer.update(secret);
return Buffer.concat([encrypted, cipherer.final()]).toString("hex");
}
catch (error) {
console.error(error);
}
};
exports.cipher = cipher;
const decipher = (encrypted) => {
if (!encrypted) {
return "";
}
try {
const textParts = encrypted.split(":");
const encryptedData = Buffer.from(textParts.join(":"), "hex");
const decipherer = (0, crypto_1.createDecipheriv)("aes-256-cbc", key, iv);
const decrypted = decipherer.update(encryptedData);
return Buffer.concat([decrypted, decipherer.final()]).toString();
}
catch (error) {
console.error(error);
}
};
exports.decipher = decipher;
//# sourceMappingURL=crypto.js.map
;