Examples
Every example is a complete script. Copy it into your project, or press Run to execute it in your browser with the current version of @peculiar/x509. The examples use the platform's WebCrypto (globalThis.crypto), which browsers and Node.js 20+ provide.
Certificates
- Read a certificate: subject, issuer, validity, public key, and typed extensions from a PEM file.
- Create a self-signed certificate: a CA certificate with Basic Constraints and Key Usage, exported as PEM.
- Issue and verify a certificate: a CA signs a server certificate, and
verify()checks it against the issuer. - Distinguished names: parse, build, and read names in string and JSON form.
Certificate requests
- Create a certificate request: a PKCS#10 CSR with requested extensions and a challenge password.
- Issue a certificate from a request: verify a CSR and issue a certificate for its key.
Revocation
- Create and check a CRL: revoke serial numbers with a reason, verify the CRL, and look up a certificate.
Chains and bundles
- Build a certificate chain: order certificates from a leaf up to its root.
- PKCS#7 files and PEM bundles: read and write
.p7bfiles and lists of PEM certificates.