Convert PEM-Encoded CSR to DER-Encoded using OpenSSL

Convert PEM-Encoded CSR to DER-Encoded using OpenSSL

In the realm of digital security, Certificate Signing Request (CSR) play an important role in obtaining digital certificate. However, different systems and applications may require certificates in different formats. One common task involves converting a PEM-encoded CSR to a DER-encoded. This tutorial explains how to convert PEM-encoded CSR to DER-encoded using OpenSSL.

Let's say we have the following PEM-encoded CSR:

-----BEGIN CERTIFICATE REQUEST-----
MIIBEjCBvQIBADBYMQswCQYDVQQGEwJVUzEVMBMGA1UECgwMVGVzdCBDb21wYW55
MR8wHQYDVQQLDBZUZXN0IE9yZ2FuaXphdGlvbiBVbml0MREwDwYDVQQDDAh0ZXN0
LmNvbTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQCzI+L79VcDMExRpc7nO0q5Yy9w
RKVlS5MfBCRFv7yb3VjjrQWdRzT5Wl5etQOot5G8czA9xxtWijx/C+tB6N3RAgMB
AAGgADANBgkqhkiG9w0BAQsFAANBAFpF4SkUp8oILW6nQJ/lC9+p/9QnF4/kWlAx
/vt3zyHWTVJcDIlUkMjFj8rFeHMJqslhTMvgbcBxhl6U6gQM7iA=
-----END CERTIFICATE REQUEST-----

To convert the PEM-encoded CSR to DER-encoded, run the following command:

openssl req -in test.csr -outform DER -out test_der.csr

The meaning of options:

  • -in test.csr - specifies the input file, which, in this case, is the PEM-encoded CSR file.
  • -outform DER - instructs that the output format should be DER.
  • -out test_der.csr - designates the output file name for the DER-encoded CSR.

If you have a DER-encoded CSR and want to change it back to PEM-encoded, use this OpenSSL command:

openssl req -in test_der.csr -inform DER -out test.csr

Leave a Comment

Cancel reply

Your email address will not be published.