This commit is contained in:
Tben
2023-08-13 14:00:04 +01:00
parent 98c4c17eb3
commit 43287b0329
25 changed files with 2106 additions and 230 deletions
-4
View File
@@ -14,7 +14,6 @@ const { Buffer } = require("buffer");
const decrypt = ({ encryptedString, encryptionKey, encryptionSalt }) => {
if (!encryptedString?.match(/./)) {
console.log("Encrypted string is invalid");
console.log("Encrypted string =>", encryptedString);
return encryptedString;
}
@@ -40,9 +39,6 @@ const decrypt = ({ encryptedString, encryptionKey, encryptionSalt }) => {
return decrypted;
} catch (error) {
console.log("Error in decrypting =>", error.message);
console.log("encryptedString =>", encryptedString);
console.log("encryptionKey =>", encryptionKey);
console.log("encryptionSalt =>", encryptionSalt);
return encryptedString;
}
};
+14 -1
View File
@@ -3,7 +3,19 @@
const { scryptSync, createCipheriv } = require("crypto");
const { Buffer } = require("buffer");
/**
*
* @param {object} param0
* @param {string} param0.data
* @param {string} param0.encryptionKey
* @param {string} param0.encryptionSalt
* @returns {string | null}
*/
const encrypt = ({ data, encryptionKey, encryptionSalt }) => {
if (!data?.match(/./)) {
console.log("Encryption string is invalid");
return data;
}
if (!encryptionKey?.match(/.{8,}/)) {
console.log("Encryption key is invalid");
return data;
@@ -25,7 +37,8 @@ const encrypt = ({ data, encryptionKey, encryptionSalt }) => {
encrypted += cipher.final("hex");
return encrypted;
} catch (error) {
return null;
console.log("Error in encrypting =>", error.message);
return data;
}
};
+4 -1
View File
@@ -1,3 +1,5 @@
// @ts-check
const { createHmac } = require("crypto");
/**
@@ -6,7 +8,8 @@ const { createHmac } = require("crypto");
* @returns {string}
*/
module.exports = function hashPassword(password) {
const hmac = createHmac("sha512", process.env.ENCRYPTION_PASSWORD);
const encryptionKey = process.env.DSQL_ENCRYPTION_KEY || "";
const hmac = createHmac("sha512", encryptionKey);
hmac.update(password);
let hashed = hmac.digest("base64");
return hashed;