Node.JS bindings for PolarSSL, a clean, lightweight crypto library.
PolarSSL is a lot easier to reason about than OpenSSL, and has a nicer API that
can be exposed in node with less abstraction. Hopefully this module will be able
to form the base of an alternative for the built-in crypto
and tls
modules.
Right now everything here is very very fluid. API's might change with a moment's notice, and the version of this module on npm will likely be out of date. Please clone directly from git://github.com/deoxxa/node-polarssl.git if you want to see how things are doing.
Most of this stuff mirrors the core crypto api, so take a look at the official docs for more details. If an implemented method in this module doesn't behave as specified in the official docs, it's a bug. There are some additional methods as well, so read through this list for the whole story.
var cipher = polarssl.createCipher("ARC4-128", key=Buffer("..."), iv=Buffer("..."));
This is a duplex stream - write cleartext in, get ciphertext out.
var cipher = new polarssl.Cipher("md5");
cipher.update(Buffer("this is some data"));
cipher.updateAsync(Buffer("this is some data"), function(err) {
if (err) {
return console.warn(err);
}
});
var data = cipher.final();
cipher.finalAsync(function(err, data) {
if (err) {
return console.warn(err);
}
console.log(data);
});
var decipher = polarssl.createDecipher("ARC4-128", key=Buffer("..."), iv=Buffer("..."));
This is a duplex stream - write ciphertext in, get cleartext out.
var decipher = new polarssl.Decipher("md5");
decipher.update(Buffer("this is some data"));
decipher.updateAsync(Buffer("this is some data"), function(err) {
if (err) {
return console.warn(err);
}
});
var data = decipher.final();
decipher.finalAsync(function(err, data) {
if (err) {
return console.warn(err);
}
console.log(data);
});
var hash = polarssl.createHash("md5");
This is a duplex stream - write data in, get digest out on end()
.
var hash = new polarssl.Hash("md5");
hash.update(Buffer("this is some data"));
hash.updateAsync(Buffer("this is some data"), function(err) {
if (err) {
return console.warn(err);
}
});
var digest = hash.digest();
hash.digestAsync(function(err, digest) {
if (err) {
return console.warn(err);
}
console.log(digest);
});
var hmac = polarssl.createHMAC("md5", "whatever");
This is a duplex stream - write data in, get digest out on end()
.
var hmac = new polarssl.HMAC("md5", "whatever");
hmac.update(Buffer("this is some data"));
hmac.updateAsync(Buffer("this is some data"), function(err) {
if (err) {
return console.warn(err);
}
});
var digest = hmac.digest();
hmac.digestAsync(function(err, digest) {
if (err) {
return console.warn(err);
}
console.log(digest);
});
var keygen = polarssl.createKeygen();
var keygen = new polarssl.Keygen();
var key = keygen.generateKey();
var key = new polarssl.KeyRSA();
var pem = key.format();
var data = polarssl.randomBytes(100);
All original code is licensed under a 3-clause BSD license. A copy is included with the source.
PolarSSL is licensed under GPLv2.
- GitHub (deoxxa)
- Twitter (@deoxxa)
- Email (deoxxa@fknsrs.biz)