fs = require 'fs'
crypto = require 'crypto'
ursa = require 'ursa'
salt = 'lK4qA0RY8TRMq8duxRup'fs = require 'fs'
crypto = require 'crypto'
ursa = require 'ursa'
salt = 'lK4qA0RY8TRMq8duxRup'Create a random symmetrical key.
bytes is the size of the key to create. (Number)cb(err, key) is optional and will make the operation asynchronous.
(Function)exports.createRandom = (bytes = 48, cb) -> crypto.randomBytes bytes, cbCreate a random RSA private key, from which the public key can be derived.
bytes is the size of the key to create. (Number)exp is the exponent to use. (Number)exports.createPrivate = (bytes = 256, exp = 65537) ->
ursa.generatePrivateKey bytes * 8, expGenerate a pseudo-random symmetrical key from a password asynchronously.
password is the password to use. (String)bytes is the size of the key to create. (Number)cb(err, key) will be called when finished. (Function)exports.fromPassword = (password, bytes = 32, cb) ->
crypto.pbkdf2 password, salt, 4096, bytes, cbGenerate a pseudo-random symmetrical key from a password synchronously. (See above.)
exports.fromPasswordSync = (password, bytes = 32) ->
crypto.pbkdf2Sync password, salt, 4096, bytesLoad a PEM encoded RSA public key asynchronously.
loc is the location of the public key file. (String)cb(err, pubKey) will be called when finished. (Function)exports.loadPublicKey = (loc, cb) ->
fs.readFile loc, (err, data) ->
if err? then cb err, null
else cb null, ursa.createPublicKey dataLoad a PEM encoded RSA public key synchronously. (See above.)
exports.loadPublicKeySync = (loc) ->
data = fs.readFileSync loc
ursa.createPublicKey dataLoad a PEM encoded RSA private key asynchronously.
loc is the location of the private key file. (String)cb(err, privKey) will be called when finished. (Function)exports.loadPrivateKey = (loc, cb) ->
fs.readFile loc, (err, data) ->
if err? then cb err, null
else cb null, ursa.createPrivateKey dataLoad a PEM encoded RSA private key synchronously. (See above)
exports.loadPrivateKeySync = (loc) ->
data = fs.readFileSync loc
ursa.createPrivateKey data