webapi-eca/js/encryption.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-04-19 01:49:48 +00:00
// 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);