RSAKeyPair¶
-
class
gafaelfawr.keypair.RSAKeyPair(private_key: cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization)¶ Bases:
objectAn RSA key pair with some simple helper functions.
Notes
Created by calling
generate()orfrom_pem()rather than the constructor.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: bytes) → gafaelfawr.keypair.RSAKeyPair¶ Import an RSA key pair from a PEM-encoded private key.
Parameters: pem ( bytes) – The PEM-encoded key (must not be password-protected).Returns: keypair – The corresponding key pair. Return type: RSAKeyPair
-
classmethod
generate() → gafaelfawr.keypair.RSAKeyPair¶ Generate a new RSA key pair.
Returns: keypair – Newly-generated key pair. Return type: RSAKeyPair
-
private_key_as_pem() → bytes¶ Return the serialized private key.
Returns: key – Private key encoded using PKCS#8 with no encryption. Return type: bytes
-
public_key_as_jwks(kid: Optional[str] = None) → Dict[str, str]¶ Return the public key in JWKS format.
Parameters: kid ( str, optional) – The key ID. If not included, the kid will be omitted, making the result invalid JWKS.Returns: key – The public key in JWKS format. Return type: Dict[ str,str]
-
public_key_as_pem() → bytes¶ Return the PEM-encoded public key.
Returns: public_key – The public key in PEM encoding and SubjectPublicKeyInfo format. Return type: bytes
-
public_numbers() → cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicNumbers¶ Return the public numbers for the key pair.
Returns: nums – The public numbers. Return type: cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicNumbers
-
classmethod