{ PEM Formatter }

// normalize line breaks and block wrappers for pem files

Format, validate, and normalize PEM certificates, private keys, and certificate chains. Fix line breaks, block wrappers, and encoding issues instantly in your browser.

Paste one or multiple PEM blocks — certificates, private keys, CSRs, or chains.

🔐

Ready to format

Paste a PEM block and click Format PEM

HOW TO USE

  1. 01
    Paste PEM input

    Paste one or multiple PEM blocks into the text area — certificates, private keys, CSRs, or full certificate chains.

  2. 02
    Choose output format

    Select formatted (standard 64-char line wrap), single line, or raw base64 body only.

  3. 03
    Format and copy

    Click Format PEM. Each block is normalized and labeled. Copy individual blocks or all at once.

FEATURES

Normalize line breaks 64-char wrapping Block type detection Chain splitting Base64 validation Browser-based

USE CASES

  • 🔧 Fix mangled PEM files copied from emails or terminals
  • 🔧 Normalize certificates before deploying to Nginx or Apache
  • 🔧 Split certificate chains into individual blocks
  • 🔧 Validate and inspect CSR files before submitting to a CA
  • 🔧 Convert single-line PEM to properly wrapped format

WHAT IS THIS?

PEM (Privacy Enhanced Mail) is the most common format for SSL/TLS certificates, private keys, and certificate chains. It uses Base64-encoded DER data wrapped in -----BEGIN ... ----- header and footer lines.

This tool normalizes any broken, malformed, or single-line PEM data back to the RFC 7468 standard: 64-character line wrapping with proper headers and footers.

RELATED TOOLS

FREQUENTLY ASKED QUESTIONS

What is a PEM file?

PEM stands for Privacy Enhanced Mail. It's a Base64-encoded format for storing cryptographic objects like X.509 certificates, private keys, and certificate signing requests (CSRs). PEM files are identified by their -----BEGIN...----- and -----END...----- header lines.

Why do PEM files get corrupted?

PEM corruption usually happens when files are copied through email clients, chat apps, or terminals that re-wrap text. Sometimes the Base64 body gets merged into a single line, or newlines are replaced with spaces or other characters. This tool detects and fixes all of these issues.

What's the correct line length for PEM?

According to RFC 7468, PEM Base64 data must be wrapped at 64 characters per line. Some older implementations use 76 characters, but 64 is the modern standard used by OpenSSL, Nginx, Apache, and most TLS libraries.

Can I format a full certificate chain?

Yes! Paste the entire chain (root CA + intermediates + server certificate) and the tool will split and format each block individually. Each block is labeled and can be copied separately or all together.

Is this tool safe to use with private keys?

Yes. All processing happens entirely in your browser using JavaScript and PHP server-side — your data is never stored, logged, or sent to any third party. You can also inspect the source code directly in your browser's developer tools.

What PEM block types are supported?

This tool supports all standard PEM block types including CERTIFICATE, PRIVATE KEY, RSA PRIVATE KEY, EC PRIVATE KEY, PUBLIC KEY, CERTIFICATE REQUEST, NEW CERTIFICATE REQUEST, DH PARAMETERS, CERTIFICATE REVOCATION LIST, and more.

What's the difference between PEM, DER, and PFX?

PEM is Base64-encoded DER with ASCII headers — human-readable. DER is the raw binary format. PFX (also called PKCS#12) is a binary archive that can bundle the certificate and private key together. This tool handles PEM format only.

How do I verify a formatted PEM with OpenSSL?

After formatting, you can verify a certificate with: openssl x509 -in cert.pem -noout -text. For private keys: openssl rsa -in key.pem -check. For CSRs: openssl req -in csr.pem -noout -verify.

What Is a PEM Formatter and Why Do You Need One?

PEM (Privacy Enhanced Mail) is the de facto standard encoding format for SSL/TLS certificates, private keys, certificate signing requests (CSRs), and certificate revocation lists (CRLs). Despite its name, PEM has nothing to do with email — it was originally designed for secure mail exchange in the 1990s, but the format stuck around and became ubiquitous in the world of public key infrastructure (PKI).

A properly formatted PEM file follows a strict structure: a -----BEGIN TYPE----- header line, the DER-encoded cryptographic data converted to Base64 and wrapped at exactly 64 characters per line, followed by a -----END TYPE----- footer. When this structure breaks — which happens frequently when PEM data is copy-pasted across chat apps, emails, CI/CD environment variables, or documentation — the result is a certificate or key that OpenSSL and most TLS libraries will simply refuse to parse.

💡 Need premium SSL-ready web templates and security-focused UI kits? MonsterONE offers unlimited downloads of professional web development assets — worth checking out.

Common Causes of Malformed PEM Files

PEM corruption is surprisingly common in real-world workflows. Here are the most frequent causes developers encounter:

How PEM Formatting Works

The PEM Formatter tool normalizes malformed PEM data through a series of steps:

  1. Block detection: The tool scans the input for all -----BEGIN ... ----- and -----END ... ----- marker pairs, supporting every standard PEM block type.
  2. Base64 extraction: All whitespace (spaces, tabs, carriage returns, newlines) is stripped from the body content between the headers, leaving clean Base64 data.
  3. Validation: The extracted Base64 is validated against the standard character set (A-Z, a-z, 0-9, +, /, =). Any invalid characters are flagged with a clear error message.
  4. Re-wrapping: The clean Base64 data is re-wrapped at 64 characters per line, conforming to RFC 7468 and the OpenSSL standard.
  5. Block reconstruction: The header and footer are reattached, producing a syntactically valid PEM block.

PEM Block Types Explained

The -----BEGIN TYPE----- header identifies the cryptographic object contained in the PEM block. Understanding these types helps you verify you have the right data for your use case:

Certificate Chains and Bundle Files

A certificate chain (also called a bundle or CA bundle) is a PEM file containing multiple concatenated certificate blocks. A typical chain includes the server certificate, one or more intermediate CA certificates, and optionally the root CA certificate. Web servers like Nginx and Apache accept these bundles directly as the ssl_certificate or SSLCertificateChainFile directive.

This PEM Formatter automatically detects multiple blocks in your input and splits them for individual inspection. You can see each block's type, line count, and byte size, then copy them individually or all together in the correct chain order.

PEM vs DER vs PFX: When to Use Each

While PEM is the most human-friendly format, there are cases where other encodings are required. DER is the raw binary encoding of the same data — smaller in size but not human-readable or copy-pasteable. It's commonly used in Java environments and some older middleware. PFX / PKCS#12 is a binary archive format that bundles the certificate and private key together, password-protected. It's the standard on Windows and commonly used for importing/exporting certificates in IIS and Azure. This tool handles PEM only; use OpenSSL to convert between formats with openssl pkcs12 or openssl x509 -outform der.

Storing PEM Certificates in Environment Variables

One of the most common real-world PEM problems occurs when teams store certificates or private keys in environment variables for Docker, Kubernetes, GitHub Actions, or other CI/CD systems. Most systems strip newlines from env var values, converting a properly formatted multi-line PEM into a single broken string.

The solution is to either store the Base64-encoded single-line version and decode it at runtime, or use the newline escape sequence (\n) as a placeholder. This tool's "single line" output mode is ideal for generating the compact form you need for env vars — just wrap it back when needed.

Verifying Your PEM Files with OpenSSL

After formatting, you should always verify the result with OpenSSL before deploying. Here are the essential commands: