Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A cryptographic module for node.js

tree: 0f9ad50452

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README
Octocat-spinner-32 crypto.cc Added finaltol to Decipher as a .final method that tolerates block pa…
Octocat-spinner-32 package.json
Octocat-spinner-32 test.js
Octocat-spinner-32 test_cert.pem first commit
Octocat-spinner-32 test_key.pem first commit
Octocat-spinner-32 wscript Added Cipher, Decipher methods
README
node-crypto
===========

A wrapper around openssl for node.js, currently exposing Hashing, Signing
and Verifying methods.

Version 0.0.3 : Added cipher / decipher, thanks to Frans-Willem Hardijzer.

To install, ensure that you have openssl installed, and run:

node-waf configure 
node-waf build

This will put the crypto.node binary module in build/default. 

The hashing, signing and verifying methods can work with binary, hex or 
base64 encoded strings.

The encrypt / decrypt methods work with binary, hex or base64 encodings,
with streaming.

Quick example
-------------

var sys=require("sys");
var posix=require('posix');
var crypto=require("./crypto");

// Test hashing
var h1 = (new crypto.Hash).init("sha1").update("Test123").digest("hex");
var h2 = (new crypto.Hash).init("sha1").update("Test").update("123").digest("hex");
sys.puts(h1===h2);

// Load our public and private keys
var keyPem = posix.cat("test_key.pem").wait();
var certPem = posix.cat("test_cert.pem").wait();

// Test signing and verifying
var s1 = (new crypto.Sign).init("RSA-SHA256").update("Test123").sign(keyPem, "base64");
sys.puts((new crypto.Verify).init("RSA-SHA256").update("Test").update("123").verify(certPem, s1, "base64"));

// Test encryption and decryption
var plaintext="Keep this a secret? No! Tell everyone about node.js!";

var cipher=(new crypto.Cipher).init("aes192", "MySecretKey123");
var ciph=cipher.update(plaintext, 'utf8', 'hex'); 
ciph+=cipher.final('hex');
sys.puts(ciph);
Something went wrong with that request. Please try again.