@@ -15,8 +15,8 @@ CryptoJWT deals with keys by defining 4 'layers'.
15
15
a number of formats and can export a key as a JWK _.
16
16
3. A :py:class: `cryptojwt.key_bundle.KeyBundle ` keeps track of a set of
17
17
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.
20
20
21
21
22
22
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
29
29
signed JSON Web Token (JWS _).
30
30
What to do ?
31
31
32
+ Staring with no key
33
+ ...................
34
+
32
35
Well if you know what kind of key you want, and if it is a asymmetric key you
33
36
want, you can use one of the provided factory methods.
34
37
@@ -50,6 +53,9 @@ If you want a symmetric key you only need some sort of "secure random"
50
53
mechanism. You can use this to acquire a byte array of the appropriate length
51
54
(e.g. 32 bytes for AES256), which can be used as a key.
52
55
56
+ When you have a key in a file on your hard drive
57
+ ................................................
58
+
53
59
If you already has a key, like if you have a PEM encoded private RSA key in
54
60
a file on your machine you can load it this way::
55
61
86
92
>>> ec_key.has_private_key()
87
93
True
88
94
95
+ Exporting keys
96
+ ..............
97
+
89
98
When it comes to exporting keys, a :py:class: `cryptojwt.jwk.JWK ` instance
90
99
only know how to serialize into the format described in JWK _.
91
100
@@ -106,7 +115,7 @@ only know how to serialize into the format described in JWK_.
106
115
}
107
116
108
117
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.
110
119
You can also get the values for the private key like this::
111
120
112
121
>>> 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:
267
276
268
277
**Note* that the default issuer ID is the empty string ''.
269
278
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
+
270
296
To import a JWKS you could do it by first creating a key bundle::
271
297
272
298
>>> from cryptojwt.key_bundle import KeyBundle
0 commit comments