mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-16 22:10:31 +00:00
29 lines
750 B
CoffeeScript
29 lines
750 B
CoffeeScript
###
|
|
|
|
Encryption
|
|
===============
|
|
> Handles RSA encryption and decryption of user specific parameters.
|
|
###
|
|
|
|
# **Loads Modules:**
|
|
|
|
# - [cryptico](https://github.com/wwwtyro/cryptico)
|
|
cryptico = require 'my-cryptico'
|
|
|
|
exports = module.exports = ( args ) =>
|
|
@log = args.logger
|
|
@oPrivateRSAkey = cryptico.generateRSAKey args[ 'keygen' ], 1024
|
|
@strPublicKey = cryptico.publicKeyString @oPrivateRSAkey
|
|
@log.info "DM | Public Key generated: #{ @strPublicKey }"
|
|
module.exports
|
|
|
|
exports.getPublicKey = () =>
|
|
@strPublicKey
|
|
|
|
exports.encrypt = ( plainText ) =>
|
|
oEncrypted = cryptico.encrypt plainText, @strPublicKey
|
|
oEncrypted.cipher
|
|
|
|
exports.decrypt = ( strEncrypted ) =>
|
|
oDecrypted = cryptico.decrypt strEncrypted, @oPrivateRSAkey
|
|
oDecrypted.plaintext
|