Hope I got the terms correct.I currently have an EC public key in the form -----BEGIN PUBLIC KEY-----xxxxx-----END PUBLIC KEY-----which I understand is the SubjectPublicKeyInfo form. I would like to convert this into the form -----BEGIN EC PUBLIC KEY-----xxxxx-----END EC PUBLIC KEY-----using commands like openssl or similar. I can't seem to find a RSAPublicKey_{in|out} for the openssl ec command. I would like to be able to convert the public key in both DER and PEM forms.Is there any other way to do this?
Convert EC Public Key from SubjectPublicKeyInfo form into traditional form
openssl
OpenSSL does not support any BEGIN EC PUBLIC KEY format and (AFAIK) no such format exists. There is a traditional public key format for RSA (BEGIN RSA PUBLIC KEY), which is essentially a PEM encoded PKCS#1 structure. Later standards defined how to encode public keys in an algorithm agnostic way (SubjectPublicKeyInfo) and so there isn't always a traditional format version.You can check the known OpenSSL PEM types by looking in the openssl pem header file (include/openssl/pem.h). You will notice that there is no EC PUBLIC KEY entry. There is an RSA PUBLIC KEY, DSA PUBLIC KEY and ECDSA PUBLIC KEY, but the latter two are not used anywhere in the OpenSSL codebase (i.e. they only exist in the header file).There are traditional formats for private keys. To convert a PKCS8 private key to traditional form use:openssl ec -in p8file.pem -out tradfile.pemThe ec command also recognises the -inform DER and -outform DER options. So, for example, to convert a DER PKCS8 private key file into PEM traditional you could use:openssl ec -inform DER -in p8file.der -out tradfile.pemOr to convert a PEM PKCS8 private key file into DER traditional use:openssl ec -in p8file.pem -outform DER -out tradfile.derYou can also go the other way, i.e. traditional form private key to PKCS8:openssl pkcs8 -topk8 -nocrypt -in tradfile.pem -out p8file.pemThe pkcs8 command above also recognises the -inform and -outform options.