# What Is PEM (Privacy-Enhanced Mail encoding)?

> PEM is a text encoding that wraps Base64-encoded DER data between BEGIN and END lines, the most common way to store certificates and keys.

Source: https://ssl.sh/glossary/pem/
Last updated: 2026-11-10

PEM is the textual encoding used for most certificates, keys and CSRs on Unix-like systems. It takes the binary [DER](https://ssl.sh/glossary/der/) encoding of an object, Base64-encodes it in lines of 64 characters, and wraps it between a header and footer naming the object type, such as `BEGIN CERTIFICATE`, `BEGIN PRIVATE KEY` or `BEGIN CERTIFICATE REQUEST`. The name comes from the Privacy-Enhanced Mail standards of the early 1990s; that email system never caught on, but its encoding survived, and [RFC 7468](https://www.rfc-editor.org/rfc/rfc7468) now documents it for PKIX, PKCS and CMS structures.

## Why it matters
PEM is what nginx, Apache, HAProxy, Postfix, curl and most Linux tools expect. Because it is plain text, one file can hold several objects in sequence, which is how a [fullchain](https://ssl.sh/glossary/fullchain/) file or a [CA bundle](https://ssl.sh/glossary/ca-bundle/) works, and it survives copy and paste into control panels and configuration management. Knowing that PEM is only a wrapper around DER makes format conversion straightforward.

## Example
```text
-----BEGIN CERTIFICATE-----
MIIDdzCCAl+gAwIBAgIUJ3...(Base64, 64 characters per line)...
-----END CERTIFICATE-----
```

```bash
openssl x509 -in example.com.pem -outform DER -out example.com.der
```

## Common misconceptions
- **PEM is a type of certificate.** It is an encoding; the same certificate can be stored as PEM or DER.
- **A .pem file always contains a certificate.** It may hold a key, a CSR, a chain, or several of these together.
- **Small edits do not matter.** Missing dashes, a truncated BEGIN line or deleted characters in the Base64 body make the file unreadable.

## Related terms

- [DER](https://ssl.sh/zh/glossary/der/): DER 是 ASN.1 的二进制编码规则，保证每个值只有唯一一种字节表示，X.509 证书和密钥都以它为基础。
- [X.509](https://ssl.sh/zh/glossary/x509/): X.509 是 ITU-T 制定的公钥证书标准格式，其互联网配置规范 RFC 5280 规定了 TLS 所用证书的结构和验证方法。
- [CRT 文件](https://ssl.sh/zh/glossary/crt-file/): CRT 文件是存放 X.509 证书的 .crt 或 .cer 文件，内容可能是 PEM 文本，也可能是二进制 DER，取决于生成它的平台。
- [KEY 文件](https://ssl.sh/zh/glossary/key-file/): KEY 文件是按惯例存放私钥的 .key 文件，通常为 PEM 编码，但扩展名本身并不说明里面的具体格式。
- [fullchain](https://ssl.sh/zh/glossary/fullchain/): fullchain 是依次包含站点证书和中间证书的 PEM 文件，让客户端能把站点证书连到受信任的根证书。
- [CA Bundle](https://ssl.sh/zh/glossary/ca-bundle/): CA Bundle 是把多张 PEM 证书拼接在一起的文件，既可能是服务器要发送的中间证书链，也可能是客户端信任的根证书集合。
- [PKCS#12](https://ssl.sh/zh/glossary/pkcs12/): PKCS#12 是一种用口令保护的二进制容器格式，可以把私钥、证书和证书链打包进一个文件，扩展名通常是 .p12 或 .pfx。
