Skip to main content
Version: 4.0

Overview

phpseclib's File namespace handles the file formats that appear throughout public-key cryptography - certificates, certificate requests, key bundles, revocation lists, and signed/encrypted/compressed message containers. This page is a map of what's covered and how the pieces fit together.

The two families of File formats

The formats split into two groups:

Identity & key material

These describe who someone is and what keys they hold. They're the building blocks of PKI.

FormatWhat it isClass
X.509A certificate - a public key bound to an identity, signed by a CAphpseclib4\File\X509
CSRA Certificate Signing Request - what you send to a CA to get an X.509 cert issuedphpseclib4\File\CSR
SPKACA simpler alternative to CSRs (Signed Public Key And Challenge)phpseclib4\File\SPKAC
CRLA Certificate Revocation List - what a CA publishes to announce that previously-issued certs are no longer validphpseclib4\File\CRL
PFXA bundle (PKCS #12) that packages a private key together with its certificate (and often a chain), optionally encrypted with a passwordphpseclib4\File\PFX

Message wrapping

These take an arbitrary payload and do something to it - sign it, encrypt it, hash it, compress it - producing a self-describing container that another implementation can unwrap. All four are variants of the Cryptographic Message Syntax.

FormatWhat it doesClass
SignedDataSigns a payload so recipients can verify origin and integrityphpseclib4\File\CMS\SignedData
EncryptedDataEncrypts a payload with a symmetric keyphpseclib4\File\CMS\EncryptedData
DigestedDataAttaches a hash of a payload (no signature)phpseclib4\File\CMS\DigestedData
CompressedDataCompresses a payload, typically as an inner layer before signing or encryptingphpseclib4\File\CMS\CompressedData

CMS containers stack. To sign-then-encrypt a payload, you wrap it in a SignedData and then wrap that in an EncryptedData.

Identifying a file by its contents

If the file looks like...It's probably...
-----BEGIN CERTIFICATE-----An X.509 certificate → X.509
-----BEGIN CERTIFICATE REQUEST-----A CSR → CSR
-----BEGIN X509 CRL-----A CRL → CRL
.p12 or .pfx extensionA PFX bundle → PFX
.p7m, .p7s, or -----BEGIN CMS-----A CMS container - use CMS::load() and let it dispatch
Starts with MII… (no PEM header)Base64-encoded DER - try X.509 or CSR first; the load methods will tell you if you've guessed wrong

For CMS containers specifically, you don't need to know the variant in advance - CMS::load() reads the contentType field and returns the appropriate subclass. See CMS Overview for details.

Deep dives

Two pages cover the machinery underneath every class on this list:

  • Constructed Objects - the generic ASN.1 container class that everything else is built on. Worth reading if you need to manipulate fields the higher-level classes don't expose, or if you're building your own wrapper.
  • Distinguished Names - the structure used for issuer and subject fields throughout X.509, CSR, and CRL.

Both are linked from the sidebar under "Deep Dives."