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 useopenssl 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 useopenssl pkcs12
.– hkotsubo
@hkotsubo the key is yes RSA but the file . der only contains the private key.
– Filipe Moraes