Extract private key from file with extension . DER

Asked

Viewed 184 times

2

I need to extract the private key from a file .DER, however analyzing the function openssl_pkey_get_private I identified that it is necessary to pass as parameter a file with extension .PEM.

I tried to see the contents of the certificate using the following command:

openssl x509 -in certificate.der -inform der -text -noout

However the following error occurred:

Unable to load Certificate

140492645532928:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:Wrong tag:.. /Crypto/asn1/tasn_dec. c:1112: 140492645532928:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:.. /Crypto/asn1/tasn_dec. c:274:Type=X509_CINF 140492645532928:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:.. /Crypto/asn1/tasn_dec. c:609:Field=cert_info, Type=X509

I tried to convert the format .DEM for the format .PEM using the following command, but a file with the format is required .CRT that I don’t have:

openssl x509 -in certificate.crt -inform der -outform pem -out cert.pem



You can extract the private key from a file with extension .DER?

  • If I’m not mistaken x509 only works if the file contains a certificate (without the private key). If the file contains only the key, an alternative to convert it is to use openssl rsa (assuming that the key is RSA). If the file contains the certificate and the private key (it is a pfx, jks, etc.), you can use openssl pkcs12.

  • @hkotsubo the key is yes RSA but the file . der only contains the private key.

1 answer

1


If I’m not mistaken x509 only works if the file contains a certificate (without the private key).

As in your case the file only has the RSA private key (as stated in the comments), the option rsa should work. To convert it from DER to PEM, do:

openssl rsa -inform der -outform pem -in chaveprivada.der -out chaveprivada.pem

With that, the file chaveprivada.der is converted to PEM, and the result will be in the file chaveprivada.pem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.