mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-16 22:10:31 +00:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
// Generated by CoffeeScript 1.7.1
|
|
|
|
/*
|
|
|
|
Encryption
|
|
===============
|
|
> Handles RSA encryption and decryption of user specific parameters.
|
|
*/
|
|
|
|
(function() {
|
|
var cryptico, exports;
|
|
|
|
cryptico = require('my-cryptico');
|
|
|
|
exports = module.exports = (function(_this) {
|
|
return function(args) {
|
|
_this.log = args.logger;
|
|
_this.oPrivateRSAkey = cryptico.generateRSAKey(args['keygen'], 1024);
|
|
_this.strPublicKey = cryptico.publicKeyString(_this.oPrivateRSAkey);
|
|
_this.log.info("DM | Public Key generated: " + _this.strPublicKey);
|
|
return module.exports;
|
|
};
|
|
})(this);
|
|
|
|
exports.getPublicKey = (function(_this) {
|
|
return function() {
|
|
return _this.strPublicKey;
|
|
};
|
|
})(this);
|
|
|
|
exports.encrypt = (function(_this) {
|
|
return function(plainText) {
|
|
var oEncrypted;
|
|
oEncrypted = cryptico.encrypt(plainText, _this.strPublicKey);
|
|
return oEncrypted.cipher;
|
|
};
|
|
})(this);
|
|
|
|
exports.decrypt = (function(_this) {
|
|
return function(strEncrypted) {
|
|
var oDecrypted;
|
|
oDecrypted = cryptico.decrypt(strEncrypted, _this.oPrivateRSAkey);
|
|
return oDecrypted.plaintext;
|
|
};
|
|
})(this);
|
|
|
|
}).call(this);
|