updates
This commit is contained in:
+46
-46
@@ -1,46 +1,46 @@
|
||||
// @ts-check
|
||||
|
||||
const { scryptSync, createDecipheriv } = require("crypto");
|
||||
const { Buffer } = require("buffer");
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {string} param0.encryptedString
|
||||
* @param {string} param0.encryptionKey
|
||||
* @param {string} param0.encryptionSalt
|
||||
* @returns
|
||||
*/
|
||||
const decrypt = ({ encryptedString, encryptionKey, encryptionSalt }) => {
|
||||
if (!encryptedString?.match(/./)) {
|
||||
console.log("Encrypted string is invalid");
|
||||
return encryptedString;
|
||||
}
|
||||
|
||||
if (!encryptionKey?.match(/.{8,}/)) {
|
||||
console.log("Decrption key is invalid");
|
||||
return encryptedString;
|
||||
}
|
||||
|
||||
if (!encryptionSalt?.match(/.{8,}/)) {
|
||||
console.log("Decrption salt is invalid");
|
||||
return encryptedString;
|
||||
}
|
||||
|
||||
const algorithm = "aes-192-cbc";
|
||||
|
||||
let key = scryptSync(encryptionKey, encryptionSalt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
const decipher = createDecipheriv(algorithm, key, iv);
|
||||
|
||||
try {
|
||||
let decrypted = decipher.update(encryptedString, "hex", "utf8");
|
||||
decrypted += decipher.final("utf8");
|
||||
return decrypted;
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log("Error in decrypting =>", error.message);
|
||||
return encryptedString;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = decrypt;
|
||||
// @ts-check
|
||||
|
||||
const { scryptSync, createDecipheriv } = require("crypto");
|
||||
const { Buffer } = require("buffer");
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {string} param0.encryptedString
|
||||
* @param {string} param0.encryptionKey
|
||||
* @param {string} param0.encryptionSalt
|
||||
* @returns
|
||||
*/
|
||||
const decrypt = ({ encryptedString, encryptionKey, encryptionSalt }) => {
|
||||
if (!encryptedString?.match(/./)) {
|
||||
console.log("Encrypted string is invalid");
|
||||
return encryptedString;
|
||||
}
|
||||
|
||||
if (!encryptionKey?.match(/.{8,}/)) {
|
||||
console.log("Decrption key is invalid");
|
||||
return encryptedString;
|
||||
}
|
||||
|
||||
if (!encryptionSalt?.match(/.{8,}/)) {
|
||||
console.log("Decrption salt is invalid");
|
||||
return encryptedString;
|
||||
}
|
||||
|
||||
const algorithm = "aes-192-cbc";
|
||||
|
||||
let key = scryptSync(encryptionKey, encryptionSalt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
const decipher = createDecipheriv(algorithm, key, iv);
|
||||
|
||||
try {
|
||||
let decrypted = decipher.update(encryptedString, "hex", "utf8");
|
||||
decrypted += decipher.final("utf8");
|
||||
return decrypted;
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log("Error in decrypting =>", error.message);
|
||||
return encryptedString;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = decrypt;
|
||||
|
||||
+45
-45
@@ -1,45 +1,45 @@
|
||||
// @ts-check
|
||||
|
||||
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;
|
||||
}
|
||||
if (!encryptionSalt?.match(/.{8,}/)) {
|
||||
console.log("Encryption salt is invalid");
|
||||
return data;
|
||||
}
|
||||
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = encryptionKey;
|
||||
|
||||
let key = scryptSync(password, encryptionSalt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
const cipher = createCipheriv(algorithm, key, iv);
|
||||
|
||||
try {
|
||||
let encrypted = cipher.update(data, "utf8", "hex");
|
||||
encrypted += cipher.final("hex");
|
||||
return encrypted;
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log("Error in encrypting =>", error.message);
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = encrypt;
|
||||
// @ts-check
|
||||
|
||||
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;
|
||||
}
|
||||
if (!encryptionSalt?.match(/.{8,}/)) {
|
||||
console.log("Encryption salt is invalid");
|
||||
return data;
|
||||
}
|
||||
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = encryptionKey;
|
||||
|
||||
let key = scryptSync(password, encryptionSalt, 24);
|
||||
let iv = Buffer.alloc(16, 0);
|
||||
const cipher = createCipheriv(algorithm, key, iv);
|
||||
|
||||
try {
|
||||
let encrypted = cipher.update(data, "utf8", "hex");
|
||||
encrypted += cipher.final("hex");
|
||||
return encrypted;
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log("Error in encrypting =>", error.message);
|
||||
return data;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = encrypt;
|
||||
|
||||
+27
-27
@@ -1,27 +1,27 @@
|
||||
/** # MODULE TRACE
|
||||
======================================================================
|
||||
* Detected 4 files that call this module. The files are listed below:
|
||||
======================================================================
|
||||
* `require` Statement Found in [add-user.js] => file:///d:\GitHub\dsql\engine\user\add-user.js
|
||||
* `require` Statement Found in [login-user.js] => file:///d:\GitHub\dsql\engine\user\login-user.js
|
||||
* `require` Statement Found in [googleLogin.js] => file:///d:\GitHub\dsql\engine\user\social\utils\googleLogin.js
|
||||
* `require` Statement Found in [update-user.js] => file:///d:\GitHub\dsql\engine\user\update-user.js
|
||||
==== MODULE TRACE END ==== */
|
||||
|
||||
// @ts-check
|
||||
|
||||
const { createHmac } = require("crypto");
|
||||
|
||||
/**
|
||||
* # Hash password Function
|
||||
* @param {object} param0
|
||||
* @param {string} param0.password - Password to hash
|
||||
* @param {string} param0.encryptionKey - Encryption key
|
||||
* @returns {string}
|
||||
*/
|
||||
module.exports = function hashPassword({ password, encryptionKey }) {
|
||||
const hmac = createHmac("sha512", encryptionKey);
|
||||
hmac.update(password);
|
||||
let hashed = hmac.digest("base64");
|
||||
return hashed;
|
||||
};
|
||||
/** # MODULE TRACE
|
||||
======================================================================
|
||||
* Detected 4 files that call this module. The files are listed below:
|
||||
======================================================================
|
||||
* `require` Statement Found in [add-user.js] => file:///d:\GitHub\dsql\engine\user\add-user.js
|
||||
* `require` Statement Found in [login-user.js] => file:///d:\GitHub\dsql\engine\user\login-user.js
|
||||
* `require` Statement Found in [googleLogin.js] => file:///d:\GitHub\dsql\engine\user\social\utils\googleLogin.js
|
||||
* `require` Statement Found in [update-user.js] => file:///d:\GitHub\dsql\engine\user\update-user.js
|
||||
==== MODULE TRACE END ==== */
|
||||
|
||||
// @ts-check
|
||||
|
||||
const { createHmac } = require("crypto");
|
||||
|
||||
/**
|
||||
* # Hash password Function
|
||||
* @param {object} param0
|
||||
* @param {string} param0.password - Password to hash
|
||||
* @param {string} param0.encryptionKey - Encryption key
|
||||
* @returns {string}
|
||||
*/
|
||||
module.exports = function hashPassword({ password, encryptionKey }) {
|
||||
const hmac = createHmac("sha512", encryptionKey);
|
||||
hmac.update(password);
|
||||
let hashed = hmac.digest("base64");
|
||||
return hashed;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user