-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrypto.js
37 lines (28 loc) · 1008 Bytes
/
crypto.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
function cryptoEncrypt(stringToCrypto) {
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'abcdefg';
function encrypt(text){
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
var hw = encrypt(stringToCrypto)
console.log(hw);
generatedCrypto.innerHTML += "<br> your crypted text : " + hw;
}
function decryptCrypto(cryptoToString) {
var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'abcdefg';
function decrypt(text){
var decipher = crypto.createDecipher(algorithm,password)
var dec = decipher.update(text,'hex','utf8')
dec += decipher.final('utf8');
return dec;
}
var decryptedString = decrypt(cryptoToString)
console.log(decryptedString);
generatedDecryptedCrypto.innerHTML += "<br> your crypted text : " + decryptedString;
}