Compare commits

..

4 Commits

Author SHA1 Message Date
dignifiedquire
fba4d3cc0f chore: release version v0.4.0 2016-05-23 12:38:14 +02:00
dignifiedquire
d8f8717a16 chore: update contributors 2016-05-23 12:38:14 +02:00
Friedel Ziegelmayer
6b4a1ab7a3 Merge pull request #1 from ipfs/fixes
fix: some issues found when using in libp2p-secio
2016-05-23 12:36:53 +02:00
Friedel Ziegelmayer
18810aca86 fix: some issues found when using in libp2p-secio 2016-05-23 12:31:45 +02:00
4 changed files with 36 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "libp2p-crypto",
"version": "0.3.1",
"version": "0.4.0",
"description": "Crypto primitives for libp2p",
"main": "lib/index.js",
"jsnext:main": "src/index.js",

View File

@@ -30,7 +30,7 @@ module.exports = (curveName) => {
}
return {
key: priv.getPublic(),
key: new Buffer(priv.getPublic('hex'), 'hex'),
genSharedKey
}
}

View File

@@ -19,7 +19,11 @@ class RsaPublicKey {
verify (data, sig) {
const md = forge.md.sha256.create()
md.update(data, 'utf8')
if (Buffer.isBuffer(data)) {
md.update(data.toString('binary'), 'binary')
} else {
md.update(data)
}
return this._key.verify(md.digest().bytes(), sig)
}
@@ -60,9 +64,13 @@ class RsaPrivateKey {
sign (message) {
const md = forge.md.sha256.create()
md.update(message, 'utf8')
return this._privateKey.sign(md)
if (Buffer.isBuffer(message)) {
md.update(message.toString('binary'), 'binary')
} else {
md.update(message)
}
const raw = this._privateKey.sign(md, 'RSASSA-PKCS1-V1_5')
return new Buffer(raw, 'binary')
}
get public () {

View File

@@ -112,4 +112,26 @@ describe('RSA', () => {
})
})
})
it('sign and verify', () => {
const data = new Buffer('hello world')
const sig = key.sign(data)
expect(
key.public.verify(data, sig)
).to.be.eql(
true
)
})
it('does fails to verify for different data', () => {
const data = new Buffer('hello world')
const sig = key.sign(data)
expect(
key.public.verify(new Buffer('hello'), sig)
).to.be.eql(
false
)
})
})