forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
34 lines (29 loc) · 877 Bytes
/
utils.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
var crypto = require('crypto');
var algo = 'aes-256-ctr';
var password = 'itsasecret!';
function serializeAddress(address) {
return JSON.stringify(address);
}
function deserializeAddress(json) {
return JSON.parse(json);
}
function encrypt(input) {
var cipher = crypto.createCipher(algo, password);
var encrypted = cipher.update(input, 'utf8', 'hex');
encrypted += cipher.final('hex');
return encrypted;
}
function descrypt(cryptedInput) {
var decipher = crypto.createDecipher(algo, password);
var decryted = decipher.update(cryptedInput, 'hex', 'utf8');
decryted += decipher.final('utf8');
return decryted;
}
module.exports = {
serializeAddress: function (address) {
return encrypt(serializeAddress(address));
},
deserializeAddress: function (input) {
return deserializeAddress(descrypt(input));
}
};