Skip to content

Commit

Permalink
node stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin Metcalf committed Nov 15, 2014
1 parent d55225f commit 342c74f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
8 changes: 1 addition & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
var sign = require('./sign');
var Writable = require('readable-stream').Writable;
var inherits = require('inherits');
exports.createSign = createSign;
function createSign(algorithm) {

}
require('./inject')(module.exports, require('crypto'));
61 changes: 61 additions & 0 deletions inject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
var sign = require('./sign');
var verify = require('./verify');
var Writable = require('readable-stream').Writable;
var inherits = require('inherits');
var algos = require('./algos');
module.exports = function (exports, crypto) {
exports.createSign = createSign;
function createSign(algorithm) {
var data = algos[algorithm];
return new Sign(crypto.createHash(data.hash));
}
exports.createVerify = createVerify;
function createVerify(algorithm) {
var data = algos[algorithm];
return new Verify(crypto.createHash(data.hash));
}
};
inherits(Sign, Writable);
function Sign(hash) {
Writable.call(this)
this._hash = hash;
};
Sign.prototype._write = function _write(data, _, done) {
this._hash.update(data);
done();
};
Sign.prototype.update = function update(data) {
this.write(data);
};

Sign.prototype.sign = function sign(key, enc) {
this.end();
var hash = this._hash.digest();
var sig = sign(hash, key);
if (enc) {
sig = sig.toString(enc);
}
return sig;
};

inherits(Verify, Writable);
function Verify(hash) {
Writable.call(this)
this._hash = hash;
};
Verify.prototype._write = function _write(data, _, done) {
this._hash.update(data);
done();
};
Verify.prototype.update = function update(data) {
this.write(data);
};

Verify.prototype.verify = function verify(key, sig, enc) {
this.end();
var hash = this._hash.digest();
if (!Buffer.isBuffer(sig)) {
sig = new Buffer(sig, enc);
}
return verify(sig, hash, key);
};
15 changes: 15 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
browserify-sign
===

a package to duplicate the functionality of node's crypto public key functions, much of this is based on [Fedor Indutny's](https://github.com/indutny) work on [tls.js](https://github.com/indutny/tls.js).

# done

- basic rsa signing and verifying with the right api

# todo

- tests to make sure we actually did it
- chinese remainder theorom?
- eliptical curve signing
- publicEncrypt and privateDecrypt?

0 comments on commit 342c74f

Please sign in to comment.