-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
23 lines (20 loc) · 734 Bytes
/
test.js
File metadata and controls
23 lines (20 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const crypto = require('crypto');
function aesEncrypt(data,key){
const cipher = crypto.createCipheriv('aes-192-ccm',key);
var crypted = cipher.update(data,'utf8','hex');
crypted += cipher.final('hex');
return crypted;
}
function aesDecrypt(encrypted, key){
const decipher = crypto.createDecipheriv('aes-192-ccm',key);
var decrypted = decipher.update(encrypted,'hex','utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
var data = 'Hello, this is a secret message!';
var key = 'Password!';
var encrypted = aesEncrypt(data,key);
var decrypted = aesDecrypt(encrypted,key);
console.log('Plain text:'+data);
console.log('Encrypted text:'+encrypted);
console.log('Decrypted text:'+decrypted);