-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Calvin Metcalf
committed
Nov 15, 2014
1 parent
d55225f
commit 342c74f
Showing
3 changed files
with
77 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |