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))| Selector | kty / crv | Key objects |
|---|---|---|
OCT | oct | bytes |
RSA | RSA | RSAPrivateKey, RSAPublicKey |
ECDSA | EC, P-256 / P-384 / P-521 | ECDSAPrivateKey, ECDSAPublicKey |
ECDH | EC, P-256 / P-384 / P-521 | ECDHPrivateKey, ECDHPublicKey |
ED25519 | OKP, Ed25519 | Ed25519PrivateKey, Ed25519PublicKey |
ED448 | OKP, Ed448 | Ed448PrivateKey, Ed448PublicKey |
X25519 | OKP, X25519 | X25519PrivateKey, X25519PublicKey |
X448 | OKP, X448 | X448PrivateKey, 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.