-
Notifications
You must be signed in to change notification settings - Fork 0
/
AES.js
58 lines (40 loc) · 1.16 KB
/
AES.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
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
54
55
56
57
58
var forge = require('node-forge');
function () {
console.log("........ ");
encryptData("1234",function(res){
if (res != null) {
console.log("E >>>>>>> ",res);
}
});
decryptData("3I5KNoWMWXB29jdkmRTwHA==",function(res){
if (res != null) {
console.log("D >>>>>>> ",res);
}
});
console.log("fin.");
};
function encryptData(dataToCrypt, call){
let key = 'e51ef23d5e9c18789794d114f56e59c7';
let iv = 'AODVNUASDNVVAOVF';
let algo = 'AES-CBC';
let cipher = forge.cipher.createCipher(algo, key);
cipher.start({iv: iv});
cipher.update(forge.util.createBuffer(dataToCrypt));
cipher.finish();
let encrypted = cipher.output;
let resultat = forge.util.encode64(encrypted.data);
call(resultat);
}
function decryptData(dataToDecrypt, call){
let key = 'e51ef23d5e9c18789794d114f56e59c7';
let iv = 'AODVNUASDNVVAOVF';
let algo = 'AES-CBC';
let decodedB64 = forge.util.decode64(dataToDecrypt);
let decipher = forge.cipher.createDecipher(algo, key);
decipher.start({iv: iv});
decipher.update(forge.util.createBuffer(decodedB64));
decipher.finish();
let decrypt = decipher.output;
let result = decrypt.data;
call(result);
}