RSAKeyPair

class gafaelfawr.keypair.RSAKeyPair(private_key)

Bases: object

An RSA key pair with some simple helper functions.

Notes

Created by calling generate() or from_pem() rather than the constructor.

Parameters:

private_key (RSAPrivateKey)

Methods Summary

from_pem(pem)

Import an RSA key pair from a PEM-encoded private key.

generate()

Generate a new RSA key pair.

private_key_as_pem()

Return the serialized private key.

public_key_as_jwks([kid])

Return the public key in JWKS format.

public_key_as_pem()

Return the PEM-encoded public key.

public_numbers()

Return the public numbers for the key pair.

Methods Documentation

classmethod from_pem(pem)

Import an RSA key pair from a PEM-encoded private key.

Parameters:

pem (bytes) – The PEM-encoded key (must not be password-protected).

Returns:

The corresponding key pair.

Return type:

RSAKeyPair

Raises:

cryptography.exceptions.UnsupportedAlgorithm – Raised if the provided key is not an RSA private key.

classmethod generate()

Generate a new RSA key pair.

Returns:

Newly-generated key pair.

Return type:

RSAKeyPair

private_key_as_pem()

Return the serialized private key.

Returns:

Private key encoded using PKCS#8 with no encryption.

Return type:

bytes

public_key_as_jwks(kid=None)

Return the public key in JWKS format.

Parameters:

kid (str | None, default: None) – The key ID. If not included, the kid will be omitted, making the result invalid JWKS.

Returns:

The public key in JWKS format.

Return type:

JWKS

public_key_as_pem()

Return the PEM-encoded public key.

Returns:

The public key in PEM encoding and SubjectPublicKeyInfo format.

Return type:

bytes

public_numbers()

Return the public numbers for the key pair.

Returns:

The public numbers.

Return type:

cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicNumbers