Blame view

app/controllers/decrypt.js 650 Bytes
2201e360   Geoffrey PREUD'HOMME   Le login se fait ...
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
  var ursa = require('ursa');
  var fs = require('fs');
  
  var decrypt = {};
  
  decrypt.decrypter = false;
  
  decrypt.whenOk = function (cb) {
    if (this.encrypter) {
      cb();
    } else {
      this.prepare(cb);
    }
  };
  
  decrypt.prepare = function (cb) {
    fs.readFile('config/ci_com.pem', function(err, data) {
      if (err) {
        throw err;
      }
      this.decrypter = ursa.createPrivateKey(data);
      cb();
    });
  };
  
  decrypt.preload = function(cb) {
    this.whenOk(cb);
  };
  
  decrypt.decrypt = function (string, cb) {
    this.whenOk(function() {
      cb(this.decrypter.decrypt(string, 'base64', 'utf8', ursa.RSA_PKCS1_PADDING));
    });
  };
  
  module.exports = decrypt;