0

I need to convert a CSR file in PEM encoding to a DER encoded file.

This is the openssl command for that but I need to do it in Java without BouncyCastle.

openssl req -inform pem -outform der -in file_one.csr -out file_two.der

What is the equivalent code for this in Java?

jww
  • 90,984
  • 81
  • 374
  • 818
Hulk Man
  • 143
  • 1
  • 12

1 Answers1

1

The PEM is the Base64 encoding of the binary DER with header an trailer lines. Just ignore the header and trailer and use Base64.Decoder on the content and there you are.

Jonathan Rosenne
  • 2,083
  • 18
  • 25
  • 1
    I would recommend to parse instead of ignore header and trailer. Otherwise you won't recognize special cases like multiple certificates in one PEM files (not uncommon). – Robert Jan 01 '18 at 13:07