Skip to content

deoxxa/node-polarssl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-polarssl

Node.JS bindings for PolarSSL, a clean, lightweight crypto library.

RIDE THE POWER

Overview

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.

Warning

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.

Functionality

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.

polarssl.createCipher

var cipher = polarssl.createCipher("ARC4-128", key=Buffer("..."), iv=Buffer("..."));

polarssl.Cipher

This is a duplex stream - write cleartext in, get ciphertext out.

var cipher = new polarssl.Cipher("md5");

polarssl.Cipher.update

cipher.update(Buffer("this is some data"));

polarssl.Cipher.updateAsync

cipher.updateAsync(Buffer("this is some data"), function(err) {
  if (err) {
    return console.warn(err);
  }
});

polarssl.Cipher.final

var data = cipher.final();

polarssl.Cipher.finalAsync

cipher.finalAsync(function(err, data) {
  if (err) {
    return console.warn(err);
  }

  console.log(data);
});

polarssl.createDecipher

var decipher = polarssl.createDecipher("ARC4-128", key=Buffer("..."), iv=Buffer("..."));

polarssl.Decipher

This is a duplex stream - write ciphertext in, get cleartext out.

var decipher = new polarssl.Decipher("md5");

polarssl.Decipher.update

decipher.update(Buffer("this is some data"));

polarssl.Decipher.updateAsync

decipher.updateAsync(Buffer("this is some data"), function(err) {
  if (err) {
    return console.warn(err);
  }
});

polarssl.Decipher.final

var data = decipher.final();

polarssl.Decipher.finalAsync

decipher.finalAsync(function(err, data) {
  if (err) {
    return console.warn(err);
  }

  console.log(data);
});

polarssl.createHash

var hash = polarssl.createHash("md5");

polarssl.Hash

This is a duplex stream - write data in, get digest out on end().

var hash = new polarssl.Hash("md5");

polarssl.Hash.update

hash.update(Buffer("this is some data"));

polarssl.Hash.updateAsync

hash.updateAsync(Buffer("this is some data"), function(err) {
  if (err) {
    return console.warn(err);
  }
});

polarssl.Hash.digest

var digest = hash.digest();

polarssl.Hash.digestAsync

hash.digestAsync(function(err, digest) {
  if (err) {
    return console.warn(err);
  }

  console.log(digest);
});

polarssl.createHMAC

var hmac = polarssl.createHMAC("md5", "whatever");

polarssl.HMAC

This is a duplex stream - write data in, get digest out on end().

var hmac = new polarssl.HMAC("md5", "whatever");

polarssl.HMAC.update

hmac.update(Buffer("this is some data"));

polarssl.HMAC.updateAsync

hmac.updateAsync(Buffer("this is some data"), function(err) {
  if (err) {
    return console.warn(err);
  }
});

polarssl.HMAC.digest

var digest = hmac.digest();

polarssl.HMAC.digestAsync

hmac.digestAsync(function(err, digest) {
  if (err) {
    return console.warn(err);
  }

  console.log(digest);
});

polarssl.createKeygen

var keygen = polarssl.createKeygen();

polarssl.Keygen

var keygen = new polarssl.Keygen();

polarssl.Keygen.generateKey

var key = keygen.generateKey();

polarssl.KeyRSA

var key = new polarssl.KeyRSA();

polarssl.KeyRSA.format

var pem = key.format();

polarssl.randomBytes

var data = polarssl.randomBytes(100);

License

All original code is licensed under a 3-clause BSD license. A copy is included with the source.

PolarSSL is licensed under GPLv2.

Contact