dsql-admin/dsql-app/.local_dist/server/chunks/7547.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-11-05 11:12:42 +00:00
"use strict";
exports.id = 7547;
exports.ids = [7547];
exports.modules = {
/***/ 7547:
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
// @ts-check
const { scryptSync , createCipheriv } = __webpack_require__(6113);
const { Buffer } = __webpack_require__(4300);
const serverError = __webpack_require__(3017);
/**
* @async
* @param {string} data
* @param {string} [encryptionKey]
* @param {string} [encryptionSalt]
* @returns {string | null}
*/ const encrypt = (data, encryptionKey, encryptionSalt)=>{
const algorithm = "aes-192-cbc";
const password = encryptionKey ? encryptionKey : process.env.DSQL_ENCRYPTION_PASSWORD || "";
/** ********************* Generate key */ const salt = encryptionSalt ? encryptionSalt : process.env.DSQL_ENCRYPTION_SALT || "";
let key = scryptSync(password, salt, 24);
let iv = Buffer.alloc(16, 0);
// @ts-ignore
const cipher = createCipheriv(algorithm, key, iv);
/** ********************* Encrypt data */ try {
let encrypted = cipher.update(data, "utf8", "hex");
encrypted += cipher.final("hex");
return encrypted;
} catch (/** @type {any} */ error) {
serverError({
component: "encrypt",
message: error.message
});
return null;
}
};
module.exports = encrypt;
/***/ })
};
;