Skip to content

Commit 2809ddb

Browse files
committed
Added some more doc
1 parent e1981fe commit 2809ddb

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

doc/keyhandling.rst

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ CryptoJWT deals with keys by defining 4 'layers'.
1515
a number of formats and can export a key as a JWK_.
1616
3. A :py:class:`cryptojwt.key_bundle.KeyBundle` keeps track of a set of
1717
keys that has the same origin. Like being part of a JWKS_.
18-
4. A :py:class:`cryptojwt.key_jar.KeyJar` lastly is there to sort the keys
19-
by their owners/issuers.
18+
4. A :py:class:`cryptojwt.key_jar.KeyJar` lastly is there to keep the keys
19+
sorted by their owners/issuers.
2020

2121

2222
I will not describe how to deal with keys in layer 1, that is done best by
@@ -29,6 +29,9 @@ Let us start with you not having any key at all and you want to create a
2929
signed JSON Web Token (JWS_).
3030
What to do ?
3131

32+
Staring with no key
33+
...................
34+
3235
Well if you know what kind of key you want, and if it is a asymmetric key you
3336
want, you can use one of the provided factory methods.
3437

@@ -50,6 +53,9 @@ If you want a symmetric key you only need some sort of "secure random"
5053
mechanism. You can use this to acquire a byte array of the appropriate length
5154
(e.g. 32 bytes for AES256), which can be used as a key.
5255

56+
When you have a key in a file on your hard drive
57+
................................................
58+
5359
If you already has a key, like if you have a PEM encoded private RSA key in
5460
a file on your machine you can load it this way::
5561

@@ -86,6 +92,9 @@ and::
8692
>>> ec_key.has_private_key()
8793
True
8894

95+
Exporting keys
96+
..............
97+
8998
When it comes to exporting keys, a :py:class:`cryptojwt.jwk.JWK` instance
9099
only know how to serialize into the format described in JWK_.
91100

@@ -106,7 +115,7 @@ only know how to serialize into the format described in JWK_.
106115
}
107116

108117

109-
What you get when doing it like above is the representation of the public key.
118+
What you get when doing it like above is a representation of the public key.
110119
You can also get the values for the private key like this::
111120

112121
>>> from cryptojwt.jwk.rsa import new_rsa_key
@@ -267,6 +276,23 @@ Creating a key jar with your own newly minted keys you would do:
267276

268277
**Note* that the default issuer ID is the empty string ''.
269278
279+
You can also use :py:func:`cryptojwt.keyjar.init_key_jar` which will
280+
load keys from disc if they are there and if not mint new.
281+
282+
>>> from cryptojwt.key_jar import build_keyjar
283+
>>> import os
284+
>>> key_specs = [
285+
{"type": "RSA", "use": ["enc", "sig"]},
286+
{"type": "EC", "crv": "P-256", "use": ["sig"]},
287+
]
288+
>>> key_jar = init_key_jar(key_defs=key_specs,
289+
private_path='private.jwks')
290+
>>> len(key_jar.get_issuer_keys(''))
291+
3
292+
>>> os.path.isfile('private.jwks')
293+
True
294+
295+
270296
To import a JWKS you could do it by first creating a key bundle::
271297

272298
>>> from cryptojwt.key_bundle import KeyBundle

0 commit comments

Comments
 (0)