X.509 Reference

Loading Certificates

cryptography.x509. load_pem_x509_certificate ( data )

Added in version 0.7.

Deserialize a certificate from PEM encoded data. PEM certificates are base64 decoded and have delimiters that look like -----BEGIN CERTIFICATE----- .

Parameters :

data ( bytes ) – The PEM encoded certificate data.

Returns :

An instance of Certificate .

>>> from cryptography import x509
>>> cert = x509.load_pem_x509_certificate(pem_data)
>>> cert.serial_number
2
													
cryptography.x509. load_pem_x509_certificates ( data )

Added in version 39.0.0.

Deserialize one or more certificates from PEM encoded data.

This is like load_pem_x509_certificate() , but allows for loading multiple certificates (as adjacent PEMs) at once.

Parameters :

data ( bytes ) – One or more PEM-encoded certificates.

Returns :

list of Certificate

Raises :

ValueError – If there isn’t at least one certificate, or if any certificate is malformed.

cryptography.x509. load_der_x509_certificate ( data )

Added in version 0.7.

Deserialize a certificate from DER encoded data. DER is a binary format and is commonly found in files with the .cer extension (although file extensions are not a guarantee of encoding type).

Parameters :

data ( bytes ) – The DER encoded certificate data.

Returns :

An instance of Certificate .

Loading Certificate Revocation Lists

cryptography.x509. load_pem_x509_crl ( data )

Added in version 1.1.

Deserialize a certificate revocation list (CRL) from PEM encoded data. PEM requests are base64 decoded and have delimiters that look like -----BEGIN X509 CRL----- .

Parameters :

data ( bytes ) – The PEM encoded request data.

Returns :

An instance of CertificateRevocationList .

>>> from cryptography import x509
>>> from cryptography.hazmat.primitives import hashes
>>> crl = x509.load_pem_x509_crl(pem_crl_data)
>>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
True