29 lines
816 B
JavaScript
29 lines
816 B
JavaScript
|
const { LogType } = require("loguix")
|
||
|
const fs = require("fs")
|
||
|
const path = require("path")
|
||
|
var CryptoJS = require("crypto-js")
|
||
|
const { __glob } = require("./global-variables")
|
||
|
const clog = new LogType("KeyGen")
|
||
|
const config = require("./config")
|
||
|
|
||
|
const keypass = config.getFile().ENCRYPTION_KEY
|
||
|
|
||
|
setup()
|
||
|
|
||
|
function setup() {
|
||
|
if(keypass) {
|
||
|
clog.log("Clé de chiffrement trouvé et importé")
|
||
|
} else {
|
||
|
clog.error("Clé de chiffrement inconnu : Passage en mode par défaut")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports.encrypt = function (text) {
|
||
|
let encryptedText = CryptoJS.AES.encrypt(text, keypass).toString();
|
||
|
return encryptedText;
|
||
|
}
|
||
|
|
||
|
module.exports.decrypt = function(text) {
|
||
|
let decryptedText = CryptoJS.AES.decrypt(text, keypass).toString(CryptoJS.enc.Utf8);
|
||
|
return decryptedText;
|
||
|
}
|