bitchan / eccrypto

JavaScript Elliptic curve cryptography library
Creative Commons Zero v1.0 Universal
302 stars 98 forks source link

there is a prefix '04' in every public key generated #58

Closed maroodb closed 4 years ago

maroodb commented 4 years ago

Hello World I am using eccrypto to generate key pair at the clien side (javascript) and verify signature at the server side (java).

I noticed that there is always a prefix "04" added to public key using eccrypto.

example:

const privateKey = Buffer.from('e12c017eaada16e2355e85d52e366a99b6ef5b871e2a4ef15a33861cdfbc276e, 'hex')

const  publicKey = eccrypto.getPublic(privateKey); 
const publicKeyHex = publicKey.toString('hex')
 /* returns  040497cee5d2317fed4a79aeb13a6e50958ba3b928319d185c3faf05a7e0e859c0e45bfe5cec402529b92f07cf2341c44f3ca954ad727f58dfe096e9c5cafda51e7d*/

Using java security from the same privateKey I got :

97cee5d2317fed4a79aeb13a6e50958ba3b928319d185c3faf05a7e0e859c0e45bfe5cec402529b92f07cf2341c44f3ca954ad727f58dfe096e9c5cafda51e7d without leading "04"

I tried many examples and always there is a leading "04"

any explantation please ?

tetratorus commented 4 years ago

04 is the prefix for showing that the public key is in the full uncompressed format

JBaczuk commented 4 years ago

Closing as answered