Search code examples
opensslcertificatex509certificate

How do I line break X509 certificate string?


Typically, when a X509 certificate file is downloaded from another site, it consists of several lines.

-----BEGIN CERTIFICATE-----
MIIDETCCAfmgAwIBAgIJAI+TpAQ6jj2zMA0GCSqGSIb3DQEBCwUAMB8xHTAbBgNV
BAoMFE9yZ2FuaXphdGlvbiwgQ049TFNHMB4XDTIwMDUxODA1MjQxNloXDTIwMDYx
...

Do you have any criteria for break the line? Or should I just break the line to look good?

I have a one-line certificate string encoded Base64.
This certificate file is intended to be downloaded from the web.

Regards Me!


Solution

  • As per RFC 1421 and RFC 7468:

    Generators MUST wrap the base64-encoded lines so that each line consists of exactly 64 characters except for the final line, which will encode the remainder of the data (within the 64-character line boundary), and they MUST NOT emit extraneous whitespace. Parsers MAY handle other line sizes. These requirements are consistent with PEM [RFC1421].