How to convert rsa private key from .DER format to .PEM format programatically using openssl api. Manually I am able to convert using openssl exe. Kindly suggest programtically how to do this.
How to convert rsa private key from .DER format to .PEM format programatically using
Share
There are some functions in C OpenSSL API with name
i2d_*to parse an internal type (for the c programming language are structures with name X509,RSA …) to DER andd2i_*to parse DER to an internal type and this is how you can convert an x509 certificate file from DER format to PEM with the c programming language.The X.509 digital certificate is a data structure that contains, at minimum, the following fields:
the subject’s name
the issuer’s name
the validity period
source http://publib.boulder.ibm.com/infocenter/zos/v1r11/index.jsp?topic=/com.ibm.zos.r11.icha700/xcerts.htm
Which means this example is not for private keys of any type, certificate requests, certificate revocation lists. If you need to convert from these types of DER files you have to dive more into the OpenSSL API, because for example the private keys have to do with encryption and decryption.
Something @owlstead said and that is true … the PEM format is the
base64encoding of the DER format plus the header and footer. Then i wrote one more example in c, but you need to know the right header and footer to create a complete PEM file:and this example in Java:
I tried to use a method with
Base64OutputStreambut has some unexpected results on the PEM file. If you wanna check just replace thelast partwith this:I compiled it with:
and ran with:
something similar you have to do in your system.