PEM vs DER: two encodings for keys and certificates

PEM is a text wrapper around base64, and DER is the binary encoding that signatures are computed over. This page explains what each is, how post-quantum objects change handling, and which one applies to your systems.

On this page

PEM vs DER: which encoding do you need for keys and certificates?

If a vendor document or tender asks for PEM, DER, or both, the short answer is that PEM is a base64 text wrapper around DER-encoded data, and DER is the binary encoding that signatures are actually computed over. RFC 7468 describes a textual encoding for PKIX, PKCS, and CMS structures that is similar to, but not identical with, PEM. Each object sits between -----BEGIN <label>----- and -----END <label>----- lines, with base64 from RFC 4648 in between and no headers. The label tells a parser what the object is, for example CERTIFICATE, PUBLIC KEY, PRIVATE KEY, or ENCRYPTED PRIVATE KEY. Because the wrapper is only a transport form, the encoding you need depends on what the receiving system parses and what it hashes or verifies.

PKI engineers, platform engineers, security engineers, and vendor-risk reviewers meet this question most often in certificate files, private key stores, and the parts of a product that import or export keys. X.509 and CMS standards are where the rule matters most. RFC 5280 says the data to be signed in a certificate is DER-encoded and that the signature is computed over the DER-encoded tbsCertificate. RFC 7468 says data inside a PEM block must be BER with DER strongly preferred, because signatures are computed over DER, identifying hashes are taken over DER, and definite lengths help parsers estimate resources. Its guidance on CMS notes an exception for streaming, but signed and authenticated attributes should still be DER.

For a review, ask the vendor which encodings each import and export path accepts, and whether a PEM file is converted to DER before any hash or signature check runs. RFC 7468 defines no canonical text form, so comparing two PEM files byte for byte can mislead; decode both and compare the DER. Post-quantum objects are larger, so check that your tooling handles the size of ML-DSA and SLH-DSA keys and signatures in both forms, and confirm the exact RFC and version each product implements, since the post-quantum certificate and key formats are still new in the standards record.

PEM and DER side by side: what each is, where it is defined and where it appears

This table compares PEM and DER attribute by attribute, from the defining document to the labels and file extensions each one uses. Read it as a checklist: where two encodings carry the same ASN.1 content, the rows show which one is text and which one is binary, and which rules apply to each. The main takeaway is that PEM is a text wrapper around DER, so any signature, hash or comparison must be taken over the DER form.

AttributePEMDER
What the format isA textual encoding of ASN.1 structures, based on base64 between bracketing lines, similar to but not identical with the RFC 7468 formA binary encoding of ASN.1 structures using definite lengths, the form that the signing and hashing rules are computed over
Defining document and dateRFC 7468, April 2015, Proposed Standard, for PKIX, PKCS and CMS structuresThe DER rules used across PKIX structures, referenced in RFC 5280 (May 2008) for certificate data to be signed
Bracketing linesA -----BEGIN <label>----- line and a matching -----END <label>----- line around the base64 body, with no headers allowedNo bracketing lines, since the file is binary and carries the structure directly
Base64 wrappingBase64 per RFC 4648 Section 4, wrapped at exactly 64 characters per line except the last; parsers should ignore whitespace and may accept other line lengthsNot applicable, since no base64 is used
Labels that appearCERTIFICATE, PUBLIC KEY (a SubjectPublicKeyInfo), PRIVATE KEY (an unencrypted PKCS #8 structure) and ENCRYPTED PRIVATE KEYNot applicable as text labels; the object type is identified by its ASN.1 structure
File extensionsThe .pem extension is used for PEM-encoded application/pkcs8 objects, per RFC 5958The .p8 extension is registered for application/pkcs8 per RFC 5958; confirm the extension your tools expect for DER files
Canonical formRFC 7468 defines no canonical text form, so two PEM objects must be decoded and re-encoded as DER before they are comparedThe DER encoding is the form that signatures are computed over, so it is the form to compare and hash

What PEM is and what DER is, in the sources' own terms

RFC 7468, a Proposed Standard dated April 2015, documents the textual encoding used for PKIX, PKCS and CMS structures. It is similar to, but not identical with, the older PEM format it describes. Each object is bracketed by a -----BEGIN <label>----- line and a matching -----END <label>----- line, with base64 text in between. The base64 follows RFC 4648 Section 4, and the standard allows no headers inside the block. The label tells a parser what the object is, so the file is self-describing at the top.

  • Labels in use: The standard lists CERTIFICATE, PUBLIC KEY (a SubjectPublicKeyInfo), PRIVATE KEY (an unencrypted PKCS #8 structure) and ENCRYPTED PRIVATE KEY. A post-quantum key is carried under the same labels as a classical one, so the label alone does not reveal the algorithm.
  • Line wrapping: Generators must wrap base64 at exactly 64 characters per line, except the last line. Parsers should ignore whitespace and may accept other line lengths, so a file re-wrapped by a tool is usually still readable.
  • Content rule: The data inside a PEM block must be BER, with DER strongly preferred. The standard gives three reasons for DER: signatures are computed over DER, identifying hashes are taken over DER, and definite lengths let parsers estimate resources.
  • No canonical text form: RFC 7468 defines no canonical text form. Two PEM files can differ in line breaks and still wrap the same object, so comparing them directly is unreliable. Compare the decoded DER instead.
  • Practical places: The sources do not list every tool that writes PEM. Operators typically meet it in web server configuration, key stores exported for appliances, and trust bundles. Confirm the exact file type your software expects.

Before you trust a PEM file for verification, decode it and check the DER inside, not the text around it.

Which differences change handling of certificates and keys

PEM and DER carry the same ASN.1 structures, but they differ in how bytes are wrapped, compared and checked. Each card below names one handling consequence that engineers meet when they store, move, verify or inspect keys and certificates, including the larger sizes that post-quantum objects bring. Check these points before you write parsing code, comparison scripts or file-handling rules.

Signatures are computed over DER

RFC 5280 says certificate data to be signed is encoded with DER, and the signature is computed over the DER-encoded tbsCertificate. RFC 9881 applies the same rule to ML-DSA certificates and CRLs. A verifier therefore cannot check a signature against the PEM text itself: it must first strip the -----BEGIN and -----END lines, decode the base64 body, and recover the exact DER bytes that were signed. Confirm that your verification library does this decoding before it reads the TBS portion, especially when the certificate was re-wrapped by a tool that changed line breaks.

RFC 9881 text

No canonical text form to compare

RFC 7468 defines no canonical text form for PEM. Two files that hold the same certificate can differ in line wrapping, trailing whitespace or line endings and still be valid. To compare them, decode each file to base64, then to binary, and re-encode the result as DER before comparing bytes or hashes. Fingerprint comparisons made on raw PEM text will report false mismatches, so build this normalization step into any inventory or change-detection job that compares key material.

RFC 7468 text

Line-based handling of the text wrapper

RFC 7468 requires generators to wrap base64 at exactly 64 characters per line except the last, and says parsers should ignore whitespace and may accept other line lengths. Tools that split files by line, strip CRLF endings or join lines can therefore break a PEM block that a tolerant parser would accept. Binary DER files have no line structure at all, so a pipeline that moves DER files through text-oriented steps needs no such handling. Test PEM files through every step of your deployment path, including configuration management templates and copy-paste into web consoles.

Labels signal the ASN.1 inside

RFC 7468 gives standard labels such as CERTIFICATE, PUBLIC KEY, PRIVATE KEY and ENCRYPTED PRIVATE KEY. The label tells a reader which ASN.1 structure sits inside: PUBLIC KEY holds a SubjectPublicKeyInfo, and PRIVATE KEY holds an unencrypted PKCS #8 structure. A parser that trusts the label may reject a block whose content does not match it. When you receive a key, read the label before choosing a loader, and do not assume that a .pem file name identifies the content type.

Larger objects make base64 expansion visible

RFC 9881 gives ML-DSA-65 signatures of 3309 bytes and ML-DSA-65 public keys of 1952 bytes. Base64 encoding expands binary content by roughly one third, so a PEM file for the same object is noticeably larger than its DER form, and each line holds 64 characters. Handle these files with the size in mind: check that size limits in gateways, ticketing systems, configuration fields and certificate stores accept the expanded text, and check how much of the file a log or viewer displays. Confirm the exact sizes for the parameter set you deploy against RFC 9881.

How larger post-quantum keys and signatures change what gets encoded

Larger post-quantum objects matter most for PEM and DER handling because the encoding decision is tied to the size and structure of what is wrapped. RFC 9881 gives ML-DSA raw public keys of 1312, 1952 and 2592 bytes for ML-DSA-44, ML-DSA-65 and ML-DSA-87, with signatures of 2420, 3309 and 4627 bytes. RFC 9909 gives SLH-DSA signatures of 7856 to 49856 bytes across its six parameter sets, and places the raw signature directly in the BIT STRING with no extra ASN.1 wrapping. RFC 9935 gives ML-KEM public keys of 800, 1184 and 1568 octets for ML-KEM-512, ML-KEM-768 and ML-KEM-1024. Teams should check the size of every object their tooling reads or writes, because PEM blocks, file storage, certificate fields and logs all need to handle these lengths.

Private keys need extra care. RFC 9881 defines the ML-DSA private key as a CHOICE of a 32-byte seed, an expanded key of 2560, 4032 or 4896 bytes depending on the variant, or both. It recommends the seed format and says a recipient must reject a both-form key if the seed and expanded key are inconsistent. RFC 9935 makes the same split for ML-KEM, with a 64-octet seed recommended as the most compact option. Before deploying, confirm which form each component produces and accepts, since a PKCS #8 wrapper that works for one form may not suit the other.

Parsers should identify the variant by tag and not by length. RFC 9935 says so directly for ML-KEM private keys, and a length-based check can misread a seed as an expanded key or the reverse. Review any code or library that infers the parameter set from the size of the decoded value, and confirm with the vendor's documentation that it selects the variant from the ASN.1 tag or algorithm identifier. Do not rely on size alone when deciding whether a PEM or DER object is a valid post-quantum key.

How to work out whether PEM or DER applies to your systems

This sequence tells you which encoding each certificate, key and signed object in your estate uses, and whether a tool or vendor expects the PEM text wrapper or the underlying DER bytes. It ends with a written record of encoding per object type, so comparisons and signature checks run against the correct form.

  1. Inventory certificate and key file formats

    The PKI or platform team lists every certificate, key and CRL file in scope and records its file extension and encoding, such as .pem, .crt, .cer, .der, .key and .p8. Open each file in a text editor or with a viewer command. A PEM file shows readable BEGIN and END lines around base64 text, while a DER file shows binary data. The step is complete when every file in the inventory has a recorded encoding.

  2. Identify the PEM label in each block

    For each PEM file, read the label on the BEGIN and END lines, such as CERTIFICATE, PUBLIC KEY, PRIVATE KEY or ENCRYPTED PRIVATE KEY, as RFC 7468 defines them. The label tells you what the base64 payload contains, so a PUBLIC KEY block holds a SubjectPublicKeyInfo and a PRIVATE KEY block holds an unencrypted PKCS #8 structure. The output is a table mapping each file to its label, and any file with an unexpected or missing label goes to the vendor for review.

  3. Check whether tooling decodes PEM before validating

    The engineer checks each tool in the chain, including signers, validators, CA software and monitoring agents, and records whether it strips the PEM wrapper and base64 before parsing or hashing. Some tools compare the PEM text directly, and RFC 7468 notes that it defines no canonical text form, so two PEM files with the same content can differ in whitespace or line length. The step closes with a list of tools that decode PEM first and tools that do not.

  4. Confirm the form that signatures cover

    Ask each vendor whether signatures are computed over the DER encoding of the signed structure. RFC 5280 says the tbsCertificate is DER encoded and the signature is computed over that DER form, and RFC 9881 applies the same rule to ML-DSA certificates and CRLs. The vendor's written answer goes into the record for each product, and any product that signs over a different form is flagged for a test before rollout.

  5. Confirm the ML-DSA or ML-KEM profile and private key format

    The PKI or platform team asks each vendor which ML-DSA or ML-KEM parameter sets it supports, and whether private keys are stored as a seed or as an expanded key, or both. RFC 9881 recommends the seed format and requires a recipient to reject a both-form key if the seed and expanded key are inconsistent. RFC 9935 asks parsers to identify ML-KEM private key variants by tag rather than length. The output is a per-product list of supported profiles and key formats, confirmed in writing.

  6. Request the encoding from vendor documentation

    For each product, the engineer asks the vendor to point to the section of its documentation that states the encoding used for keys, certificates and signed objects, and checks that the stated encoding matches what the test files show. Where the documentation is silent, the vendor should give a written statement. Relevant references include the RFCs above, and standards such as RFC 9882 for CMS and RFC 9964 for JOSE and COSE. The step is complete when each product has a documented encoding and any gap is logged as an open question.

  7. Record the encoding per object type

    The team writes one register that lists each object type, including certificates, CRLs, private keys and signed messages, with its encoding, tool behavior and vendor confirmation. The register is reviewed by the security and PKI leads and kept with the inventory. Any change to a product version or encoding triggers a review of the affected rows before the change goes live.

Common mix-ups between PEM, DER and the objects they carry

Many confusions in post-quantum certificate and key work come from treating PEM, DER, and the structures they carry as if they were the same thing. Separating the encoding from the object inside it tells you what can be compared, converted and checked, and what must be decoded first. The four points below cover the mistakes engineers most often make when larger post-quantum keys and signatures pass through existing tooling.

PEM is not a separate certificate format

PEM is a text wrapper around the same binary structures that DER encodes, and RFC 7468 covers PKIX, PKCS and CMS objects written this way. A certificate in PEM and the same certificate in DER contain identical content, so the difference is only how the bytes are written. Before you compare, hash, or check a signature, decode the PEM back to DER, because RFC 5280 computes the signature over the DER-encoded tbsCertificate. Treating the two as distinct formats leads to signature checks that fail for no visible reason.

RFC 7468 text

Line wrapping does not change the object

Two PEM files can look different on screen yet hold the same object, because RFC 7468 requires generators to wrap base64 at exactly 64 characters per line except the last, while parsers should ignore whitespace and may accept other line lengths. A diff tool will show a change where none exists, and a file that was re-wrapped by an editor or a copy-paste step may still parse correctly. RFC 7468 also defines no canonical text form, so compare objects by decoding both to DER and comparing those bytes instead of comparing the text.

RFC 7468 text

PKCS #8 is a structure, not an encoding

PKCS #8 describes the structure that holds a private key, while PEM or DER describes how that structure is written. RFC 7468 pairs a PRIVATE KEY label with an unencrypted PKCS #8 structure, and the same structure can be stored as DER bytes or inside a PEM block. Asking whether a key is 'PKCS #8' without also asking whether it is PEM or DER leaves the question half answered, and the encoding decides whether a file can be read by a text tool or must be decoded first.

RFC 5958 text

The .pem extension does not set the encoding

A file extension is a naming convention and does not guarantee what is inside. RFC 5958 registers the application/pkcs8 media type with the .p8 extension and says PEM-encoded versions use the .pem extension, so the extension hints at the encoding but does not prove it. Always check the first line of a file, which should read as a BEGIN line for PEM, or inspect the bytes for DER, before you pass it to a tool. Misnamed files are a common cause of import errors when larger post-quantum keys are moved between systems.

RFC 5958 text

Questions readers ask about PEM and DER

Are PEM and DER the same thing?

No. DER is a binary encoding of ASN.1 structures, and PEM is a text wrapper around the same kind of data. PEM takes the DER bytes (or BER bytes, with DER strongly preferred), encodes them as base64 per RFC 4648 Section 4, and places them between -----BEGIN <label>----- and -----END <label>----- lines. RFC 7468 documents this textual encoding for PKIX, PKCS and CMS structures and says it is similar to, but not identical with, the PEM format used in earlier tooling. The practical result is that a PEM file and a DER file can hold the same certificate or key. The text form is easy to read and paste, while the binary form is what signing and parsing operate on. Confirm the exact label and the parser in your toolchain before you assume two files match.

Which encoding is newer, PEM or DER?

DER came first as the canonical encoding for ASN.1 structures, and PEM is the text wrapper built on top of it. The sources supplied for this page do not give a publication history that settles which format appeared earlier in every tool chain, so avoid stating a date for either one. What the standards do fix is the relationship: RFC 7468 (April 2015, Proposed Standard) describes the textual encoding, and RFC 5280 (May 2008) states that the data to be signed in a certificate is encoded with DER and that the signature is computed over the DER-encoded tbsCertificate. Because the signature is defined over DER, DER is the form that matters for validation. For post-quantum objects, RFC 9881 and RFC 9935 carry the same rule forward. If you need the history of a specific tool, check its release notes rather than this page.

Is PEM ever required in place of DER?

The sources supplied for this page do not describe a mandate that requires PEM, and they do not describe any mandate that requires DER. What they do show is where each form is used. RFC 5958 registers the application/pkcs8 media type with the .p8 extension and says PEM-encoded versions use the .pem extension, so PEM is a common carrier for a private key container. RFC 7468 says data inside a PEM block must be BER with DER strongly preferred, and it gives reasons: signatures are computed over DER, identifying hashes are taken over DER, and definite lengths let parsers estimate resources. RFC 7468 also notes that CMS is an exception where indefinite-length BER can suit streaming. Ask your platform owner which form each system expects on import and export, and check the product documentation for that version.

Do post-quantum certificates need a different encoding?

The sources supplied for this page do not describe a new encoding for post-quantum certificates. RFC 9881 defines the use of ML-DSA in X.509 certificates and CRLs, and it says the signatures are computed over the DER-encoded TBSCertificate or TBSCertList, the same rule RFC 5280 sets for classical certificates. RFC 9881 also requires the AlgorithmIdentifier parameters to be absent and assigns OIDs 2.16.840.1.101.3.4.3.17, .18 and .19 to ML-DSA-44, ML-DSA-65 and ML-DSA-87. RFC 9935 defines ML-KEM algorithm identifiers in X.509 with the parameters field absent. What changes is the size of the objects. RFC 9881 gives ML-DSA-44, ML-DSA-65 and ML-DSA-87 raw public keys of 1312, 1952 and 2592 bytes and signatures of 2420, 3309 and 4627 bytes. Larger objects affect file size, transport and buffer handling, not the encoding rule itself. Test the sizes in your own pipeline.

Can I convert between PEM and DER without changing the object?

Yes, if the conversion is only a change of wrapper. A PEM object is base64 text around the same BER or DER bytes, so decoding the base64 and writing the bytes out yields the DER object, and wrapping DER bytes in the label lines yields the PEM. RFC 7468 notes that it defines no canonical text form, so two PEM files can differ in whitespace or line length even when the object inside is the same. RFC 7468 requires generators to wrap base64 at exactly 64 characters per line except the last, and says parsers should ignore whitespace and may accept other line lengths. To compare two objects, decode both to DER and compare the bytes, not the text. Check that the converted file still parses with the label your consumer expects, such as CERTIFICATE, PUBLIC KEY, PRIVATE KEY or ENCRYPTED PRIVATE KEY.

What should I ask a vendor about encoding?

Ask which encoding each object uses at import, export and storage, and whether the product accepts both PEM and DER. Ask whether the product generates DER-encoded signed structures and whether it reads BER inside PEM blocks, since RFC 7468 prefers DER. For post-quantum keys, ask which private key format the product stores. RFC 9881 defines the ML-DSA private key as a CHOICE of a 32-byte seed, an expanded key, or both, and recommends the seed format. RFC 9935 gives ML-KEM keys a similar CHOICE with a 64-octet seed recommended as the most compact. Ask whether the product rejects a both-form key when the seed and expanded key disagree, which RFC 9881 says a recipient must do. Ask for the version and the RFC or standard each claim is based on, because the sources supplied here do not confirm that any product supports these encodings.

How DeployOpen helps teams sort out encodings during post-quantum migration

DeployOpen works through PEM and DER handling as part of the migration of the key and certificate stores a client already runs. The work starts by mapping which encodings each system reads and writes, then builds and tests the conversions and parsers needed for post-quantum objects, and documents the result for the client's own teams.

How we scope

  • Inventory which systems store keys and certificates as PEM, DER or both, and where conversions happen today.
  • Agree in writing which tools, libraries and certificate stores fall inside the engagement and which stay with the client.
  • Confirm the post-quantum object types in scope, such as ML-DSA certificates, ML-KEM keys and SLH-DSA signatures, before work starts.

How we build

  • Configure parsers and generators to decode and re-encode objects as DER before signing or hashing, as RFC 7468 and RFC 5280 require.
  • Check that larger post-quantum keys and signatures survive the PEM line-wrapping, file handling and size limits of each system.
  • Test ML-DSA private keys stored as a seed and as an expanded key for consistency, since RFC 9881 says a recipient must reject mismatched keys.

How we hand over

  • Deliver a written record of each encoding decision, the file extension used and the tool version it was tested against.
  • Document the decode and re-encode steps the client's teams must run to compare two objects, since PEM alone defines no canonical form.
  • Provide test cases and a retest plan so the client can rerun the encoding checks after upgrades or vendor changes.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after the handover is complete.
  • Support covers re-checking encodings when a library, certificate authority or key store is upgraded to a new version.
  • Confirm compatibility for the exact library and version you run, since the sources listed here do not establish it for every product.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.