JSON Web Key

JSON Web Key.

class josepy.jwk.JWK(**kwargs)[source]

Bases: josepy.json_util.TypedJSONObjectWithFields

JSON Web Key.

cryptography_key_types = ()

Subclasses should override.

required = NotImplemented

Required members of public key’s representation as defined by JWK/JWA.

thumbprint(hash_function: Callable[[], cryptography.hazmat.primitives.hashes.HashAlgorithm] = <class 'cryptography.hazmat.primitives.hashes.SHA256'>) → bytes[source]

Compute JWK Thumbprint.

https://tools.ietf.org/html/rfc7638

Returns:bytes
public_key() → josepy.jwk.JWK[source]

Generate JWK with public key.

For symmetric cryptosystems, this would return self.

classmethod load(data: bytes, password: Optional[bytes] = None, backend: Optional[Any] = None) → josepy.jwk.JWK[source]

Load serialized key as JWK.

Parameters:
  • data (str) – Public or private key serialized as PEM or DER.
  • password (str) – Optional password.
  • backend – A PEMSerializationBackend and DERSerializationBackend provider.
Raises:

errors.Error – if unable to deserialize, or unsupported JWK algorithm

Returns:

JWK of an appropriate type.

Return type:

JWK

class josepy.jwk.JWKOct(**kwargs)[source]

Bases: josepy.jwk.JWK

Symmetric JWK.

fields_to_partial_json() → Dict[str, str][source]

Serialize fields to JSON.

classmethod fields_from_json(jobj: Mapping[str, Any]) → josepy.jwk.JWKOct[source]

Deserialize fields from JSON.

public_key() → josepy.jwk.JWKOct[source]

Generate JWK with public key.

For symmetric cryptosystems, this would return self.

class josepy.jwk.JWKRSA(*args, **kwargs)[source]

Bases: josepy.jwk.JWK

RSA JWK.

Variables:keyRSAPrivateKey or RSAPublicKey wrapped in ComparableRSAKey
classmethod _encode_param(data: int) → str[source]

Encode Base64urlUInt. :type data: long :rtype: unicode

classmethod _decode_param(data: str) → int[source]

Decode Base64urlUInt.

public_key() → josepy.jwk.JWKRSA[source]

Generate JWK with public key.

For symmetric cryptosystems, this would return self.

classmethod fields_from_json(jobj: Mapping[str, Any]) → josepy.jwk.JWKRSA[source]

Deserialize fields from JSON.

fields_to_partial_json() → Dict[str, Any][source]

Serialize fields to JSON.

class josepy.jwk.JWKEC(*args, **kwargs)[source]

Bases: josepy.jwk.JWK

EC JWK.

Variables:keyEllipticCurvePrivateKey or EllipticCurvePublicKey wrapped in ComparableECKey
classmethod _encode_param(data: int, length: int) → str[source]

Encode Base64urlUInt. :type data: long :type key_size: long :rtype: unicode

classmethod _decode_param(data: str, name: str, valid_length: int) → int[source]

Decode Base64urlUInt.

fields_to_partial_json() → Dict[str, Any][source]

Serialize fields to JSON.

classmethod fields_from_json(jobj: Mapping[str, Any]) → josepy.jwk.JWKEC[source]

Deserialize fields from JSON.

public_key() → josepy.jwk.JWKEC[source]

Generate JWK with public key.

For symmetric cryptosystems, this would return self.