Extract private key from file with extension .DER

2

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

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

  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 from .DEM format to .PEM format using the following command, however I need a file with the format .CRT that I do not have:

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


Is it possible to extract the private key of a file with the .DER ?     

asked by anonymous 03.07.2018 / 13:53

1 answer

1

If I'm not mistaken the x509 option 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 rsa option should work. To convert it from DER to PEM, do:

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

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

    
03.07.2018 / 14:26