updates
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
const { scryptSync, createDecipheriv } = require("crypto");
|
||||
const { Buffer } = require("buffer");
|
||||
|
||||
const decrypt = ({ encryptedString, encryptionKey, encryptionSalt }) => {
|
||||
const algorithm = "aes-192-cbc";
|
||||
const password = encryptionKey;
|
||||
|
||||
let key = scryptSync(password, 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 (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = decrypt;
|
||||
@@ -0,0 +1,21 @@
|
||||
const { scryptSync, createCipheriv } = require("crypto");
|
||||
const { Buffer } = require("buffer");
|
||||
|
||||
const encrypt = ({ data, encryptionKey, encryptionSalt }) => {
|
||||
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 (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = encrypt;
|
||||
Reference in New Issue
Block a user