1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
JSON Web Signature (JWS)
========================
The jws Module implements the `JSON Web Signature`_ standard.
A JSON Web Signature is represented by a JWS object, related utility
classes and functions are available in this module too.
.. _JSON Web Signature: http://tools.ietf.org/html/rfc7515
Classes
-------
.. autoclass:: jwcrypto.jws.JWS
:members:
:show-inheritance:
.. autoclass:: jwcrypto.jws.JWSCore
:members:
:show-inheritance:
Variables
---------
.. autodata:: jwcrypto.jws.default_allowed_algs
Exceptions
----------
.. autoclass:: jwcrypto.jws.InvalidJWSSignature
:members:
:show-inheritance:
.. autoclass:: jwcrypto.jws.InvalidJWSObject
:members:
:show-inheritance:
.. autoclass:: jwcrypto.jws.InvalidJWSOperation
:members:
:show-inheritance:
Registries
----------
.. autodata:: jwcrypto.jws.JWSHeaderRegistry
:annotation:
Examples
--------
Sign a JWS token::
>>> from jwcrypto import jwk, jws
>>> from jwcrypto.common import json_encode
>>> key = jwk.JWK.generate(kty='oct', size=256)
>>> payload = "My Integrity protected message"
>>> jwstoken = jws.JWS(payload.encode('utf-8'))
>>> jwstoken.add_signature(key, None,
json_encode({"alg": "HS256"}),
json_encode({"kid": key.thumbprint()}))
>>> sig = jwstoken.serialize()
Verify a JWS token::
>>> jwstoken = jws.JWS()
>>> jwstoken.deserialize(sig)
>>> jwstoken.verify(key)
>>> payload = jwstoken.payload
|