Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Being unable to sign an Buffer with ECDH private key in Node.js

I'm getting a 'error:0D07209B:asn1 encoding routines:ASN1_get_object:too long' when trying to sign a object with a PrivateKey I generated, in Node.js.

The buf is a simple object encoded with node-cbor

 var ecdh = crypto.createECDH('secp256k1')
 ecdh.generateKeys()

 var sign = crypto.createSign('RSA-SHA256')
 sign.update(buf)
 var buf_signed = sign.sign('-----BEGIN PRIVATE KEY-----\n' +
                                ecdh.getPrivateKey('base64') +
                                '\n-----END PRIVATE KEY-----' +
                                '\n-----BEGIN CERTIFICATE-----' +
                                '\n-----END CERTIFICATE-----', 'binary')

Would the Certificate be strictly necessary? Am I missing any information in the PEM string?

Any help is appreciated, thank you :)

like image 957
David Dias Avatar asked Sep 03 '15 17:09

David Dias


1 Answers

It turns out I was missing that for EC Digital Signing, the right way to do it is using ECDSA.

Node.js doesn't implement it natively, but this module makes a good job of doing so:

https://www.npmjs.com/package/ecdsa

like image 144
David Dias Avatar answered Sep 28 '22 18:09

David Dias