Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signing method returns the same signature every time (for a given key and message) #54

Closed
shea256 opened this issue Sep 18, 2015 · 2 comments

Comments

@shea256
Copy link

shea256 commented Sep 18, 2015

Here's the code I'm using:

var EC = require('elliptic').ec,
    secp256k1 = new EC('secp256k1'),
    sigFormatter = require('ecdsa-sig-formatter')

var privateKeyHex = 'a5c61c6ca7b3e7e55edee68566aeab22e4da26baa285c7bd10e8d2218aa3b229',
    publicKeyHex = '027d28f9951ce46538951e3697c62588a87f1f1f295de4a14fdd4c780fc52cfe69',
    privateKeyObject = secp256k1.keyFromPrivate(privateKeyHex, 'hex'),
    publicKeyObject = secp256k1.keyFromPublic(publicKeyHex, 'hex')

var messageString = 'Hello, World',
    messageBuffer = new Buffer(messageString),
    messageBytes = messageBuffer.toJSON().data

var derSignatureObject = privateKeyObject.sign(messageBytes),
    derSignatureArray = derSignatureObject.toDER(),
    derSignatureBuffer = new Buffer(derSignatureArray),
    joseSignature = sigFormatter.derToJose(derSignatureBuffer, 'ES256')

console.log(derSignatureObject)

var verified = publicKeyObject.verify(messageBytes, derSignatureBuffer)

console.log(verified)

Is there some issue with the method or am I doing something wrong?

Thank you!

@indutny
Copy link
Owner

indutny commented Sep 18, 2015

This is because I'm using deterministic k generation for signature algorithm: http://tools.ietf.org/html/rfc6979 . Works as intended.

Thanks!

@indutny indutny closed this as completed Sep 18, 2015
@shea256
Copy link
Author

shea256 commented Sep 18, 2015

OK thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants