Unable to sign ECDH private key buffer in Node.js

I get the error: 0D07209B: asn1 encoding procedure: ASN1_get_object: too long "when trying to sign an object with the generated PrivateKey in Node.js.

Buf is a simple object encoded using 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')

Was a certificate strictly required? Is there any missing information in the PEM string?

Any help is appreciated, thanks :)

+4
source share
1 answer

It turns out I was missing that for EC Digital Signing the right way to do this is to use ECDSA.

Node.js does not implement it initially, but this module does a good job of this:

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

+1

Source: https://habr.com/ru/post/1605799/


All Articles