Can anyone help me how to convert that public key into raw-signature/binary...
The posted key is a PEM encoded key in X.509/SPKI format for curve secp384r1. This can be converted into a DER encoded key with the posted OpenSSL statement:
openssl ec -pubin -in key.pem -out out.der -outform DER
This conversion corresponds to the removal of header, footer, all line breaks and Base64 decoding of the rest.
At the end of the DER encoded key is the public key in uncompressed format (referred to as pub
in the OpenSSL printout via -text
option). The uncompressed format for secp384r1 has a length of 97 bytes (0x04|<x>|<y>
; <x>
and <y>
are the coordinates of the EC point, each 384/8=48 bytes long).
Therefore, to extract the uncompressed key from the DER encoded key, only the last 97 bytes need to be taken.
...and vice versa?
The first 23 bytes contain length information and algorithm OIDs. This byte sequence is curve-specific and its length information specifies a key in uncompressed format (i.e. the byte sequence of a different curve and/or a key in compressed format would be different). It can therefore be used as a prefix to convert a secp384r1 key in uncompressed format into a DER encoded key in X.509/SPKI format.
...but it would be better if there is any standard command using openssl...
OpenSSL does not (to my knowledge) support the direct conversion of PEM/DER encoded public keys into the uncompressed (or compressed) format or vice versa.
For the sake of completeness: With the option -conv_form compressed
in the OpenSSL statement above, the compressed format (<a>|<x>
, with <a> = 0x02
for even <y>
and <0x03>
for odd <y>
) can be used instead of the uncompressed format. This has a length of 49 bytes for secp384r1.
A DER (or PEM) encoded key can be easily analyzed when decoded with an ASN.1/DER parser, e.g. here for the posted key.