PKI-Lite - v1.0.5
    Preparing search index...

    Represents an X.509 certificate.

    An X.509 certificate is a digital certificate that binds a public key to an identity. It contains information about the certificate holder (subject), the issuer, validity period, extensions, and a digital signature from the issuer. This class provides comprehensive support for parsing, validating, and working with X.509 certificates.

    Certificate  ::=  SEQUENCE  {
         tbsCertificate       TBSCertificate,
         signatureAlgorithm   AlgorithmIdentifier,
         signatureValue       BIT STRING
    }
    
    // Load certificate from PEM
    const pem = '-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----'
    const cert = Certificate.fromPem(pem)

    // Access certificate information
    console.log('Subject:', cert.tbsCertificate.subject.commonName)
    console.log('Issuer:', cert.tbsCertificate.issuer.commonName)
    console.log('Valid from:', cert.tbsCertificate.validity.notBefore)
    console.log('Valid to:', cert.tbsCertificate.validity.notAfter)

    // Create self-signed certificate
    const selfSigned = await Certificate.createSelfSigned({
    subject: 'CN=Test Certificate, O=My Organization, C=US',
    validity: {
    notBefore: new Date('2023-01-01'),
    notAfter: new Date('2024-01-01'),
    },
    privateKeyInfo: privateKey,
    subjectPublicKeyInfo: publicKey
    })

    // Validate certificate
    const validationResult = await cert.validate({
    trustedCertificates: [caCert],
    checkRevocation: true
    })

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    signatureAlgorithm: SignatureAlgorithmIdentifier

    Algorithm used to sign this certificate.

    signatureValue: BitString

    The digital signature value from the issuer.

    tbsCertificate: TBSCertificate

    The "to be signed" certificate containing most certificate data.

    TBSCertificate: typeof TBSCertificate = TBSCertificate

    Reference to TBSCertificate class for easy access.

    Accessors

    • get pemHeader(): string

      Gets the PEM header name for this object type. Converts the class name to uppercase for use in PEM encoding.

      Returns string

    • get pkiType(): string

      Gets the PKI type name for this object (typically the class name). Used for PEM headers and debugging output.

      Returns string

    Methods

    • Compares this PKI object with another for equality. Two objects are considered equal if their DER encodings are identical.

      Parameters

      • other: PkiBase<any>

        The other PKI object to compare with

      Returns boolean

      true if the objects are equal, false otherwise

    • Parameters

      • name:
            | "SUBJECT_KEY_IDENTIFIER"
            | "KEY_USAGE"
            | "SUBJECT_ALT_NAME"
            | "BASIC_CONSTRAINTS"
            | "CRL_NUMBER"
            | "CRL_DISTRIBUTION_POINTS"
            | "CERTIFICATE_POLICIES"
            | "AUTHORITY_KEY_IDENTIFIER"
            | "EXTENDED_KEY_USAGE"
            | "AUTHORITY_INFO_ACCESS"
            | "CRL_REASON_CODE"

      Returns undefined | Extension

    • Parameters

      • name:
            | "SUBJECT_KEY_IDENTIFIER"
            | "KEY_USAGE"
            | "SUBJECT_ALT_NAME"
            | "BASIC_CONSTRAINTS"
            | "CRL_NUMBER"
            | "CRL_DISTRIBUTION_POINTS"
            | "CERTIFICATE_POLICIES"
            | "AUTHORITY_KEY_IDENTIFIER"
            | "EXTENDED_KEY_USAGE"
            | "AUTHORITY_INFO_ACCESS"
            | "CRL_REASON_CODE"

      Returns Extension[]

    • Parameters

      • Optionaloptions: {
            issuerCertificate?: Certificate;
            issuerCertificateUrls?: string[];
            ocspResponderUrls?: string[];
        }

      Returns Promise<undefined | OCSPResponse>

    • Returns a human-readable string representation of this object. By default, returns the same as toString(), but subclasses can override for more user-friendly output.

      Returns string

      A human-readable string representation