@@ -29,8 +29,8 @@ Let us start with you not having any key at all and you want to create a
2929signed JSON Web Token (JWS _).
3030What to do ?
3131
32- Well if you know what kind of key you want, if it is a asymmetric key you can
33- use one of the provided factory methods.
32+ Well if you know what kind of key you want, and if it is a asymmetric key you
33+ want, you can use one of the provided factory methods.
3434
3535 RSA
3636 :py:func: `cryptojwt.jwk.rsa.new_rsa_key `
8686 >>> ec_key.has_private_key()
8787 True
8888
89- When it comes to exporting keys a :py:class: `cryptojwt.jwk.JWK ` instance
89+ When it comes to exporting keys, a :py:class: `cryptojwt.jwk.JWK ` instance
9090only know how to serialize into the format described in JWK _.
9191
9292 >>> from cryptojwt.jwk.rsa import new_rsa_key
@@ -160,7 +160,7 @@ Key bundle
160160As mentioned above a key bundle is used to manage keys that have a common
161161origin.
162162
163- You can initiate a key bundle in serveral ways. You can use all the
163+ You can initiate a key bundle in several ways. You can use all the
164164import variants we described above and then add the resulting key to a key
165165bundle::
166166
@@ -204,14 +204,14 @@ bundle::
204204 ]
205205 }
206206
207- **Note ** that you will get a JWKS representing the public keys unless you
208- specify that you want a representation of the private keys.
207+ **Note ** that this will get you a JWKS representing the public keys.
209208
210209As an example of the special functionality of
211210:py:class: `cryptojwt.key_bundle.KeyBundle ` assume you have imported a file
212211containing a JWKS with one key into a key bundle and then some time later
213212another key is added to the file.
214- This is how key bundle deals with that::
213+
214+ First import the file with one key::
215215
216216 >>> from cryptojwt.key_bundle import KeyBundle
217217 >>> kb = KeyBundle(source="file://{}".format(fname), fileformat='jwks')
@@ -225,10 +225,13 @@ keys in the key bundle::
225225 >>> len(_keys)
226226 2
227227
228- It turns out the it contains the 2 keys that are in the file.
228+ It turns out the key bundle now contains 2 keys. Both the keys that are in the
229+ file.
230+
229231If the change is that one key is removed then something else happens.
230232Assume we add one key and remove one of the ones that was there before.
231- The file now should contain 2 keys::
233+ The file now contain 2 keys, and you might expect the key bundle to do the
234+ same::
232235
233236 >>> _keys = kb.keys()
234237 >>> len(_keys)
@@ -264,7 +267,7 @@ Creating a key jar with your own newly minted keys you would do:
264267
265268**Note* that the default issuer ID is the empty string ''.
266269
267- To import a JWKS you would do::
270+ To import a JWKS you could do it by first creating a key bundle ::
268271
269272 >>> from cryptojwt.key_bundle import KeyBundle
270273 >>> from cryptojwt.key_jar import KeyJar
@@ -291,6 +294,41 @@ The last line can also be expressed as::
291294**Note ** both variants, adds a key bundle to the list of key bundles that
292295belongs to '' it does not overwrite anything that was already there.
293296
297+ Adding a JWKS is such a common thing that there is a simpler way to do it::
298+
299+ >>> from cryptojwt.key_jar import KeyJar
300+ >>> JWKS = {
301+ "keys": [
302+ {
303+ "kty": "RSA",
304+ "e": "AQAB",
305+ "kid": "abc",
306+ "n":
307+ "wf-wiusGhA-gleZYQAOPQlNUIucPiqXdPVyieDqQbXXOPBe3nuggtVzeq7
308+ pVFH1dZz4dY2Q2LA5DaegvP8kRvoSB_87ds3dy3Rfym_GUSc5B0l1TgEob
309+ cyaep8jguRoHto6GWHfCfKqoUYZq4N8vh4LLMQwLR6zi6Jtu82nB5k8"
310+ }
311+ ]}
312+ >>> key_jar = KeyJar()
313+ >>> key_jar.import_jwks(JWKS)
314+
315+ The end result is the same as when you first created a key bundle and then
316+ added it to the key jar.
317+
318+ When dealing with signed and/or encrypted JSON Web Tokens
319+ :py:class: `cryptojwt.key_jar.KeyJar ` has these nice methods.
320+
321+ get_jwt_verify_keys
322+ :py:func: `cryptojwt.key_jar.KeyJar.get_jwt_verify_keys ` takes an
323+ signed JWT as input and returns a set of keys that
324+ can be used to verify the signature. The set you get back is a best
325+ estimate and might not contain **the ** key. How good the estimate is
326+ depends on the information present in the JWS.
327+
328+ get_jwt_decrypt_keys
329+ :py:func: `cryptojwt.key_jar.KeyJar.get_jwt_decrypt_keys ` does the
330+ same thing but returns keys that can be used to decrypt a message.
331+
294332
295333.. _cryptography : https://cryptography.io/en/latest/
296334.. _JWK : https://tools.ietf.org/html/rfc7517
0 commit comments