Skip to content

PEM (.pem)

.pem file signature | application/x-x509-cert;format=pem

PEM encoded X.509Certificate Signing Request

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

Sources: Apache Tika, Wikipedia

All Known Signatures

5 signature variants are documented for .pem files across multiple sources.

Hex Signature Offset Sources
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 0 Apache Tika, Wikipedia
2D 2D 2D 2D 2D 42 45 47 49 4E 20 43 45 52 54 49 46 49 43 41 54 45 20 52 45 51 55 45 53 54 2D 2D 2D 2D 2D 0 Wikipedia
2D 2D 2D 2D 2D 42 45 47 49 4E 20 50 52 49 56 41 54 45 20 4B 45 59 2D 2D 2D 2D 2D 0 Wikipedia
2D 2D 2D 2D 2D 42 45 47 49 4E 20 44 53 41 20 50 52 49 56 41 54 45 20 4B 45 59 2D 2D 2D 2D 2D 0 Wikipedia
2D 2D 2D 2D 2D 42 45 47 49 4E 20 52 53 41 20 50 52 49 56 41 54 45 20 4B 45 59 2D 2D 2D 2D 2D 0 Wikipedia

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);
}

How to validate .pem files in Go

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

See the full API documentation for all endpoints and parameters.

Frequently Asked Questions

What is a .pem file?

A .pem file is a PEM file. PEM encoded X.509Certificate Signing Request

What are the magic bytes for .pem files?

The magic bytes for PEM files are 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 at byte offset 0. These bytes uniquely identify the file format regardless of the file extension.

How do I validate a .pem file?

To validate a .pem file, read the first bytes of the file and compare them against the known magic bytes (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) at offset 0. This is more reliable than checking the file extension alone, as extensions can be renamed.

What is the MIME type for .pem files?

The primary MIME type for .pem files is application/x-x509-cert;format=pem.

Is it safe to open .pem files?

PEM (.pem) files are generally safe to open. They are classified as low risk because they primarily contain data rather than executable code. However, always ensure files come from a trusted source.