PEM

application/x-x509-cert;format=pem

Safe

Magic Bytes

Offset: 0
2D 2D 2D 2D 2D 42 45 47 49 4E 20 43 45 52 54 49 46 49 43 41 54 45 2D 2D 2D 2D 2D

Privacy Enhanced Mail (PEM) is a text-based file format defined by the Internet Engineering Task Force (IETF) for representing cryptographic data. It is widely employed to store and exchange X.509 certificates, private keys, and public keys within web servers, authentication systems, and TLS configurations. While originally developed for securing email, this format remains a global standard for facilitating the transfer of binary information through text-only communication channels without data corruption.

Extension

.pem

MIME Type

application/x-x509-cert;format=pem

Byte Offset

0

Risk Level

Safe

Validation Code

How to validate .pem files in Python

Python
def is_pem(file_path: str) -> bool:
    """Check if file is a valid PEM by magic bytes."""
    signature = bytes([0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D])
    with open(file_path, "rb") as f:
        return f.read(27) == signature

How to validate .pem files in Node.js

Node.js
function isPEM(buffer: Buffer): boolean {
  const signature = Buffer.from([0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D]);
  return buffer.subarray(0, 27).equals(signature);
}
Go
func IsPEM(data []byte) bool {
    signature := []byte{0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D}
    if len(data) < 27 {
        return false
    }
    return bytes.Equal(data[:27], signature)
}

API Endpoint

GET /api/v1/pem
curl https://filesignature.org/api/v1/pem

Related Formats