4

Is it possible to convert X.509 Certificate represented as a HEX string to the PEM encoded X.509 certificate? (.CER format)

1 Answer 1

9

You can try this (I suppose it is DER encoded) cat cert.txt | xxd -r -p | openssl x509 -inform DER -out mycert.pem -outform PEM

it converts it to binary and then pipes it to openssl to convert it to pem

7
  • Should be blank space separators first removed from hex dump? Also, how to convert to .cer if I have source hex dump with .hex extension?
    – user2427839
    Mar 22, 2014 at 15:21
  • doesn't matter, works either way. use the command that I've given, just use you .hex file instead of cert.txt. This should work under Linux/MacOS/Cygwin(Windows)
    – Boklucius
    Mar 23, 2014 at 14:50
  • I need output format .cer, not .pem, so I modified command: cat cert.hex | xxd -r -p | openssl x509 -inform DER -out mycert.cer -outform DER Is it correct?
    – user2427839
    Mar 23, 2014 at 16:03
  • DER is binary encoding, PEM is ascii (base64). A cer file can be either. In your question you have written PEM so the command is with PEM. If you input is alread DER there is no need to convert it again with openssl, then cat cert.hex | xxd -r -p > mycert.cert will suffice.
    – Boklucius
    Mar 23, 2014 at 18:51
  • Sorry I haven't specified that I need this for Windows, above commands is for Linux/Unix
    – user2427839
    Mar 23, 2014 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.