Skip to Content
oxcrypto

JWK

Load and dump oxcrypto keys as JSON Web Keys, and compute RFC 7638 thumbprints.

from oxcrypto.jose.jwk import JWK
from oxcrypto.signature.ed25519 import ED25519

key = ED25519.ED25519.generate()
text = JWK.ED25519.dump(key.public_key())
public = JWK.ED25519.load_public(text)
print(JWK.ED25519.thumbprint(public))
Selectorkty / crvKey objects
OCToctbytes
RSARSARSAPrivateKey, RSAPublicKey
ECDSAEC, P-256 / P-384 / P-521ECDSAPrivateKey, ECDSAPublicKey
ECDHEC, P-256 / P-384 / P-521ECDHPrivateKey, ECDHPublicKey
ED25519OKP, Ed25519Ed25519PrivateKey, Ed25519PublicKey
ED448OKP, Ed448Ed448PrivateKey, Ed448PublicKey
X25519OKP, X25519X25519PrivateKey, X25519PublicKey
X448OKP, X448X448PrivateKey, X448PublicKey

load_private requires the private members (d, or k for oct; RSA also needs p, q, dp, dq and qi); load_public reads the public members and ignores private ones, except that it rejects oct keys. A JWK whose kty or crv differs from the selector raises ValueError. dump writes only the members of RFC 7517/7518/8037 and no alg, use or kid. thumbprint returns the base64url SHA-256 thumbprint of the public members (RFC 7638, RFC 8037 section 2).

Tests use the keys and thumbprint from RFC 7515 Appendix A and RFC 8037 Appendix A, and round trips for every selector.

Zeroization

Note

Private members are base64url-decoded into wiped buffers before the key object is built. The JSON text passed to load_private and returned by dump for a private key is a Python str and is not wiped, nor are the intermediate strings serde_json creates while parsing.

On this page