forked from Neel-Shah-29/SOCIABLAST
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcryptionHandler.js
28 lines (24 loc) · 858 Bytes
/
cryptionHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const crypto = require('crypto');
const secret = 'pppppppppppppppppppppppppppppppp';
const encrypt = (Password) => {
const iv = Buffer.from(crypto.randomBytes(16));
const cipher = crypto.createCipheriv('aes-256-ctr', Buffer.from(secret), iv);
const encryptedPassword = Buffer.concat([
cipher.update(Password),
cipher.final(),
]);
return { iv: iv.toString("hex"), password: encryptedPassword.toString("hex") };
}
const decrypt = (encryption) => {
const decipher = crypto.createDecipheriv(
'aes-256-ctr',
Buffer.from(secret),
Buffer.from(encryption.iv, "hex")
);
const decryptedPassword = Buffer.concat([
decipher.update(Buffer.from(encryption.password, "hex")),
decipher.final()
])
return decryptedPassword.toString();
}
module.exports = { encrypt, decrypt };