-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
53 lines (39 loc) · 1.36 KB
/
test.js
File metadata and controls
53 lines (39 loc) · 1.36 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Node.js program to demonstrate the
// crypto.createCipheriv() method
// Includes crypto module
const crypto = require('crypto');
// Defining algorithm
const algorithm = 'aes-256-cbc';
// Defining key
const key = '11111111111111111111111111111111';
// Defining iv
const iv = '1111111111111111';
// An encrypt function
function encrypt(text) {
// Creating Cipheriv with its parameter
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key), iv);
// Updating text
let encrypted = cipher.update(text);
// Using concatenation
encrypted = Buffer.concat([encrypted, cipher.final()]);
// Returning iv and encrypted data
return { iv: iv.toString('hex'), encryptedData: encrypted.toString('hex') };
}
function decrypt(text) {
// Creating Decipheriv with its parameter
let decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(key), iv);
// Updating text
let decrypted = decipher.update(Buffer.from(text.encryptedData, 'hex'));
// Using concatenation
decrypted = Buffer.concat([decrypted, decipher.final()]);
// Returning decrypted data
return decrypted.toString();
}
// Displays output
var output = encrypt(new Date().getTime().toString() + '/zing_consumer');
var decrypted = decrypt(output);
console.log(output, decrypted, key);
// item image: only favs have image
// Rating system: Ask for additional
// Order Decline: Ask for reason
// Make database