DecryptServ.js
811 Bytes
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
var ursa = require('ursa');
var fs = require('fs');
var DecryptServ = {
decrypter: false,
whenOk: function (cb) {
if (this.encrypter) {
cb();
} else {
this.prepare(cb);
}
},
prepare: function (cb) { // TODO Juste charger au lancement du script
fs.readFile('config/ci_com.pem', function (err, data) {
if (err) {
throw err;
}
this.decrypter = ursa.createPrivateKey(data);
cb();
});
},
preload: function (cb) {
this.whenOk(cb);
},
decrypt: function (string, cb) {
this.whenOk(function () {
cb(this.decrypter.decrypt(string, 'base64', 'utf8', ursa.RSA_PKCS1_PADDING));
});
}
};
module.exports = DecryptServ;