Skip to content

Commit 5560a92

Browse files
committed
docs: add ECKey.derive_key and OKPKey.derive_key on guide
1 parent d796637 commit 5560a92

3 files changed

Lines changed: 48 additions & 4 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
A quick and simple JWT encoding and decoding would look something like this:
2323

2424
```python
25-
from joserfc import jwt
25+
from joserfc import jwt, jwk
2626
from joserfc.jwk import OctKey
2727

28-
key = OctKey.import_key("secret")
28+
key = jwk.import_key("your-secret-key", "oct")
2929
encoded = jwt.encode({"alg": "HS256"}, {"k": "value"}, key)
30-
# 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrIjoidmFsdWUifQ.ni-MJXnZHpFB_8L9P9yllj3RNDfzmD4yBKAyefSctMY'
30+
# 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJrIjoidmFsdWUifQ._M8ViO_GK6TnZ9G9eqdlS7IpNWzhoGwaYYDQ3hEwwmA'
3131

3232
token = jwt.decode(encoded, key)
3333
print(token.header)

docs/changelog.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Changelog
1212
.. module:: joserfc
1313
:noindex:
1414

15-
1.x.x
15+
1.6.0
1616
-----
1717

1818
**Unreleased**
@@ -23,6 +23,7 @@ Changelog
2323
- Improve ``generate_private_key`` method on Key's binding class.
2424
- Raise ``InvalidKeyCurveError`` when generating ECKey with an invalid curve.
2525
- Allow import key from cryptography native key types.
26+
- Add ``ECKey.derive_key`` and ``OKPKey.derive_key`` class methods.
2627

2728
1.5.0
2829
-----

docs/guide/jwk.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,31 @@ You can import an ``ECKey`` from string, bytes and a JWK (in dict).
174174
"d": "Hndv7ZZjs_ke8o9zXYo3iq-Yr8SewI5vrqd0pAvEPqg"
175175
})
176176
177+
Derive an "EC" Key
178+
~~~~~~~~~~~~~~~~~~
179+
180+
``joserfc`` provides deterministic key derivation helpers for EC key.
181+
This method allows applications to derive a *stable* JWK from an application
182+
secret (for example, ``SECRET_KEY`` in a web framework), while still producing
183+
valid cryptographic keys for use in JWS/JWE.
184+
185+
.. code-block:: python
186+
187+
from joserfc.jwk import ECKey
188+
189+
ECKey.derive_key("your-secret-key", "P-256")
190+
ECKey.derive_key("your-secret-key", "P-256", kdf_name="HKDF")
191+
192+
Supported key derivation functions:
193+
194+
- **HKDF** (recommended)
195+
- **PBKDF2** (password-based, may require higher iteration counts)
196+
197+
.. warning::
198+
Deterministic keys are useful for applications that want a stable default JWK,
199+
but **they should not be used where random key generation is required**.
200+
201+
177202
.. _OKPKey:
178203

179204
OKPKey
@@ -224,6 +249,24 @@ You can import an ``OKPKey`` from string, bytes and a JWK (in dict).
224249
"kid": "5V_IcL-iX5IbaNz9vg0CjXtWLZiJ94-ESnHI-HN1L2Y"
225250
})
226251
252+
Derive an "OKP" Key
253+
~~~~~~~~~~~~~~~~~~~
254+
255+
Just like above ``ECKey``, ``joserfc`` provides a ``OKPKey.derive_key`` method
256+
to derive a *stable* JWK.
257+
258+
.. code-block:: python
259+
260+
from joserfc.jwk import OKPKey
261+
262+
OKPKey.derive_key("your-secret-key", "Ed25519")
263+
OKPKey.derive_key("your-secret-key", "Ed25519", kdf_name="HKDF")
264+
265+
Supported key derivation functions:
266+
267+
- **HKDF** (recommended)
268+
- **PBKDF2** (password-based, may require higher iteration counts)
269+
227270
Key Set
228271
-------
229272

0 commit comments

Comments
 (0)