browserify-sign
Advanced tools
Comparing version 2.0.0 to 2.1.0
10
asn1.js
@@ -30,2 +30,12 @@ // from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js | ||
var PublicKey = rfc3280.SubjectPublicKeyInfo; | ||
exports.PublicKey = PublicKey; | ||
var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function() { | ||
this.seq().obj( | ||
this.key('version').int(), | ||
this.key('algorithm').use(rfc3280.AlgorithmIdentifier), | ||
this.key('subjectPrivateKey').octstr() | ||
); | ||
}); | ||
exports.PrivateKey = PrivateKeyInfo; | ||
var GeneralName = asn1.define('GeneralName', function() { | ||
@@ -32,0 +42,0 @@ this.choice({ |
{ | ||
"name": "browserify-sign", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -16,2 +16,4 @@ browserify-sign [![Build Status](https://travis-ci.org/calvinmetcalf/browserify-sign.svg)](https://travis-ci.org/calvinmetcalf/browserify-sign) | ||
- publicEncrypt and privateDecrypt? | ||
- other key encodings (non rss format public keys) | ||
- ~~other key encodings (non rss format public keys)~~ | ||
- dsa keys? | ||
- keys with passwords |
// much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js | ||
var pemstrip = require('pemstrip'); | ||
var asn1 = require('./asn1'); | ||
var parseKeys = require('./parseKeys'); | ||
var bn = require('bn.js'); | ||
module.exports = sign; | ||
function sign(hash, key) { | ||
var priv = asn1.RSAPrivateKey.decode(new Buffer(pemstrip.strip(key).base64, 'base64'), 'der'); | ||
var priv = parseKeys(key); | ||
var len = priv.modulus.byteLength(); | ||
@@ -9,0 +8,0 @@ var pad = [ 0, 1 ]; |
var test = require('tape'); | ||
var fs = require('fs'); | ||
var priv1024 = fs.readFileSync(__dirname + '/rsa.1024.priv'); | ||
var pub1024 = fs.readFileSync(__dirname + '/rsa.1024.pub'); | ||
var priv2028 = fs.readFileSync(__dirname + '/rsa.2028.priv'); | ||
var pub2028 = fs.readFileSync(__dirname + '/rsa.2028.pub'); | ||
var rsa1024 = { | ||
private: fs.readFileSync(__dirname + '/rsa.1024.priv'), | ||
public: fs.readFileSync(__dirname + '/rsa.1024.pub') | ||
} | ||
var rsa2028 = { | ||
private: fs.readFileSync(__dirname + '/rsa.2028.priv'), | ||
public: fs.readFileSync(__dirname + '/rsa.2028.pub') | ||
} | ||
var nonrsa1024 = { | ||
private: fs.readFileSync(__dirname + '/1024.priv'), | ||
public: fs.readFileSync(__dirname + '/1024.pub') | ||
} | ||
var nodeCrypto = require('crypto'); | ||
var myCrypto = require('../'); | ||
function testIt(pub, priv, message, scheme) { | ||
function testIt(keys, message, scheme) { | ||
var pub = keys.public; | ||
var priv = keys.private; | ||
test(message.toString(), function (t) { | ||
@@ -20,13 +31,17 @@ t.plan(4); | ||
var nodeVer = nodeCrypto.createVerify(scheme); | ||
t.ok(nodeVer.update(message).verify(pub, mySig), 'test node'); | ||
t.ok(myVer.update(message).verify(pub, nodeSig), 'test me'); | ||
t.ok(nodeVer.update(message).verify(pub, mySig), 'node validate my sig'); | ||
t.ok(myVer.update(message).verify(pub, nodeSig), 'me validate node sig'); | ||
}); | ||
} | ||
testIt(pub1024, priv1024, new Buffer('sha224 with 1024 keys'), 'RSA-SHA224'); | ||
testIt(pub2028, priv2028, new Buffer('sha224 with 2028 keys'), 'RSA-SHA224'); | ||
testIt(pub1024, priv1024, new Buffer('SHA256 with 1024 keys'), 'RSA-SHA256'); | ||
testIt(pub2028, priv2028, new Buffer('SHA256 with 2028 keys'), 'RSA-SHA256'); | ||
testIt(pub1024, priv1024, new Buffer('SHA384 with 1024 keys'), 'RSA-SHA384'); | ||
testIt(pub2028, priv2028, new Buffer('SHA384 with 2028 keys'), 'RSA-SHA384'); | ||
testIt(pub1024, priv1024, new Buffer('SHA512 with 1024 keys'), 'RSA-SHA512'); | ||
testIt(pub2028, priv2028, new Buffer('SHA512 with 2028 keys'), 'RSA-SHA512'); | ||
testIt(rsa1024, new Buffer('sha224 with 1024 keys'), 'RSA-SHA224'); | ||
testIt(nonrsa1024, new Buffer('sha224 with 1024 keys non-rsa key'), 'RSA-SHA224'); | ||
testIt(rsa2028, new Buffer('sha224 with 2028 keys'), 'RSA-SHA224'); | ||
testIt(rsa1024, new Buffer('SHA256 with 1024 keys'), 'RSA-SHA256'); | ||
testIt(nonrsa1024, new Buffer('sha256 with 1024 keys non-rsa key'), 'RSA-SHA256'); | ||
testIt(rsa2028, new Buffer('SHA256 with 2028 keys'), 'RSA-SHA256'); | ||
testIt(rsa1024, new Buffer('SHA384 with 1024 keys'), 'RSA-SHA384'); | ||
testIt(nonrsa1024, new Buffer('sha384 with 1024 keys non-rsa key'), 'RSA-SHA384'); | ||
testIt(rsa2028, new Buffer('SHA384 with 2028 keys'), 'RSA-SHA384'); | ||
testIt(rsa1024, new Buffer('SHA512 with 1024 keys'), 'RSA-SHA512'); | ||
testIt(nonrsa1024, new Buffer('sha512 with 1024 keys non-rsa key'), 'RSA-SHA512'); | ||
testIt(rsa2028, new Buffer('SHA512 with 2028 keys'), 'RSA-SHA512'); |
// much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js | ||
var pemstrip = require('pemstrip'); | ||
var asn1 = require('./asn1'); | ||
var parseKeys = require('./parseKeys'); | ||
var bn = require('bn.js'); | ||
module.exports = verify; | ||
function verify(sig, hash, key) { | ||
var pub = asn1.RSAPublicKey.decode(new Buffer(pemstrip.strip(key).base64, 'base64'), 'der'); | ||
var pub = parseKeys(key); | ||
var red = bn.mont(pub.modulus); | ||
@@ -11,0 +10,0 @@ sig = new bn(sig).toRed(red); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14831
17
270
18