I have some javascript, which generates new ECDSA public-private keypair. However all the resulting public keys which I generate seem to have fixed prefix.

This seems strange to me, since the beginning is always the same. Is this correct? Or should I expect all pub keys to be more random?

Here is example of generated public keys (base58 encoded):

  • $\begingroup$ My guess would be that the prefix is some ASN.1 structuring that also indicates the used curve and byte lengths. $\endgroup$ – SEJPM Aug 26 '17 at 12:39
  • $\begingroup$ You will need to specify what library you're talking about. Otherwise, who knows what metadata it adds to its public key format? $\endgroup$ – Squeamish Ossifrage Aug 26 '17 at 12:57
  • $\begingroup$ I thought that a binary representation of the public key is given, platform-independant, library-independant. It is not? $\endgroup$ – Tomas M Aug 26 '17 at 13:29
  • $\begingroup$ There is one fairly commonly used standard, X.509's SubjectPublicKeyInfo more conveniently described in rfc 3279 et rel, and that is what you have, but there are quite a few other formats used by some program(s) or library(ies). $\endgroup$ – dave_thompson_085 Aug 27 '17 at 1:12
  • $\begingroup$ I'm sure this is just a encoding problem and is not "cryptographically" on-topic here. How can I flag it as such? $\endgroup$ – DannyNiu Aug 28 '17 at 4:31

Your keys are ASN.1 structures. I decoded first one to hex:


When I gave this to ASN.1 parser, it shows me the next structure:

--------ObjectIdentifier 1.2.840.10045.2.1 [ecPublicKey]
--------ObjectIdentifier 1.2.840.10045.3.1.7 [prime256v1]
----BITSTRING [04405134b8399a666f12ada32f19f646f85fb7d1fc3d9aa0688bf8984a35b86ad49fbb96cfad78b994013d06d7b98c09b0104323dd0a2473cdca79342277027d3f]

So, your keys have the same prefix, because they contain algorithm identifier and curve identifier. Public key is just EC point.

| improve this answer | |
  • $\begingroup$ So, basically, if the software (javascript native crypto) generates the keys I have, is it safe to use them? Does it bring any security risk to publish the keys while they contain the identifiers? $\endgroup$ – Tomas M Aug 27 '17 at 11:11
  • $\begingroup$ No risks, secp256r1 is the most widely used curve. Even without these identifiers it is easy to guess them. $\endgroup$ – Zergatul Aug 27 '17 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.