-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (29 loc) · 1.08 KB
/
server.js
File metadata and controls
39 lines (29 loc) · 1.08 KB
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
29
30
31
32
33
34
35
36
37
38
39
// Node.js program to demonstrate the
// cipher.final() method
// Importing crypto module
const crypto = require('crypto');
const Scrypt = require("util").promisify(crypto.scrypt)
const RandomFill = require("util").promisify(crypto.randomFill)
// Creating and initializing algorithm and password
const algorithm = 'aes-192-cbc';
const password = 'Password used to generate key';
const encrypt = async (msg) => {
// Getting key for the cipher object
const key = await Scrypt(password, 'salt', 24);
const vi = await RandomFill(new Uint8Array(16))
console.log(vi)
// Creating and initializing the static iv
// const iv = Buffer.alloc(16, 0);
// const iv = Buffer.alloc(16, 0);
// Creating and initializing the cipher object
const cipher =await crypto.createCipheriv(algorithm, key, vi);
// Updating the cipher with the data
// by using update() method
let value = cipher.update(msg, 'utf8', 'hex');
// Getting buffer value
// by using final() method
value += cipher.final('hex');
// Display the result
console.log("buffer :- " + value);
}
encrypt('some clear text data')