Reputation: 101
How can I export a X509Certificate
in ASN.1 format?
I found how to export to DER and PEM, using .cer
extension, but I can not find how to export to ASN.1 format. Can anyone help me?
This is my PEM:
JcaPEMWriter pemWrt = new JcaPEMWriter(new FileWriter(path + ".cer"))
X509Certificate certificate = (X509Certificate) keyStore.getCertificate(loadCertificate);
pemWrt.writeObject(certificate);
pemWrt.flush();
pemWrt.close();
This is my DER:
X509Certificate certificate = (X509Certificate) keyStore.getCertificate(loadCertificate);
FileOutputStream fileWrite = new FileOutputStream(new File(path + ".cer"));
fileWrite.write(certificate.getEncoded());
fileWrite.flush();
fileWrite.close();
Upvotes: 2
Views: 4313
Reputation: 2613
This is very old question, but I found below OpenSSL command which covert Cert DER/PEM format data in to ASN1.
openssl asn1parse -in Cerificate.pem -inform PEM
Hope this will help someone in future.
Upvotes: 2
Reputation:
First of all, keep in mind that ASN.1 is not a format per se, it's a description language that defines a structure, and PEM is just one way to format these defined structure. (Many cryptography standards use ASN.1 to define their data structures, and PEM or DER (Distinguished Encoding Rules) to serialize those structures.)
So, PEM and DER are just 2 different ways to write information that was defined by ASN.1. You can export something to PEM or DER, but there's no such thing as "export to ASN.1 format" (because ASN.1 is not a format).
The .cer
extension is just a file extension for digital certificates, but this certificate can be either in PEM or DER (it doesn't matter, and the extension won't change).
So, when you use JcaPEMWriter
, you are already creating the file in PEM format. And when you use certificate.getEncoded()
, you are already writing the bytes in DER format.
Upvotes: 11