caesar
Version:
An easy-to-use advanced cryptography library.
77 lines (63 loc) • 1.66 kB
JavaScript
// Generated by CoffeeScript 1.7.1
(function() {
var crypto, fs, salt, ursa;
fs = require('fs');
crypto = require('crypto');
ursa = require('ursa');
salt = 'lK4qA0RY8TRMq8duxRup';
exports.createRandom = function(bytes, cb) {
if (bytes == null) {
bytes = 48;
}
return crypto.randomBytes(bytes, cb);
};
exports.createPrivate = function(bytes, exp) {
if (bytes == null) {
bytes = 256;
}
if (exp == null) {
exp = 65537;
}
return ursa.generatePrivateKey(bytes * 8, exp);
};
exports.fromPassword = function(password, bytes, cb) {
if (bytes == null) {
bytes = 32;
}
return crypto.pbkdf2(password, salt, 4096, bytes, cb);
};
exports.fromPasswordSync = function(password, bytes) {
if (bytes == null) {
bytes = 32;
}
return crypto.pbkdf2Sync(password, salt, 4096, bytes);
};
exports.loadPublicKey = function(loc, cb) {
return fs.readFile(loc, function(err, data) {
if (err != null) {
return cb(err, null);
} else {
return cb(null, ursa.createPublicKey(data));
}
});
};
exports.loadPublicKeySync = function(loc) {
var data;
data = fs.readFileSync(loc);
return ursa.createPublicKey(data);
};
exports.loadPrivateKey = function(loc, cb) {
return fs.readFile(loc, function(err, data) {
if (err != null) {
return cb(err, null);
} else {
return cb(null, ursa.createPrivateKey(data));
}
});
};
exports.loadPrivateKeySync = function(loc) {
var data;
data = fs.readFileSync(loc);
return ursa.createPrivateKey(data);
};
}).call(this);