This section contains the generic implementation of RFC7515. Find how to use it in JWS Guide.
Registered Header Parameter Names defined by Section 4.1
Defined available JWS algorithms in the registry
Generate a JWS Compact Serialization. The JWS Compact Serialization represents digitally signed or MACed content as a compact, URL-safe string, per Section 7.1.
BASE64URL(UTF8(JWS Protected Header)) || '.' ||
BASE64URL(JWS Payload) || '.' ||
BASE64URL(JWS Signature)
protected – A dict of protected header
payload – A bytes/string of payload
key – Private key used to generate signature
byte
Exact JWS Compact Serialization, and validate with the given key. If key is not provided, the returned dict will contain the signature, and signing input values. Via Section 7.1.
s – text of JWS Compact Serialization
key – key used to verify the signature
decode – a function to decode payload data
JWSObject
BadSignatureError
Generate a JWS JSON Serialization. The JWS JSON Serialization represents digitally signed or MACed content as a JSON object, per Section 7.2.
header_obj – A dict/list of header
payload – A string/dict of payload
key – Private key used to generate signature
JWSObject
Example header_obj
of JWS JSON Serialization:
{
"protected: {"alg": "HS256"},
"header": {"kid": "jose"}
}
Pass a dict to generate flattened JSON Serialization, pass a list of header dict to generate standard JSON Serialization.
Exact JWS JSON Serialization, and validate with the given key. If key is not provided, it will return a dict without signature verification. Header will still be validated. Via Section 7.2.
obj – text of JWS JSON Serialization
key – key used to verify the signature
decode – a function to decode payload data
JWSObject
BadSignatureError
Generate a JWS Serialization. It will automatically generate a
Compact or JSON Serialization depending on the given header. If a
header is in a JSON header format, it will call
serialize_json()
, otherwise it will call
serialize_compact()
.
header – A dict/list of header
payload – A string/dict of payload
key – Private key used to generate signature
byte/dict
Deserialize JWS Serialization, both compact and JSON format. It will automatically deserialize depending on the given JWS.
s – text of JWS Compact/JSON Serialization
key – key used to verify the signature
decode – a function to decode payload data
dict
BadSignatureError
If key is not provided, it will still deserialize the serialization without verification.
Header object for JWS. It combine the protected header and unprotected header together. JWSHeader itself is a dict of the combined dict. e.g.
>>> protected = {'alg': 'HS256'}
>>> header = {'kid': 'a'}
>>> jws_header = JWSHeader(protected, header)
>>> print(jws_header)
{'alg': 'HS256', 'kid': 'a'}
>>> jws_header.protected == protected
>>> jws_header.header == header
protected – dict of protected header
header – dict of unprotected header
A dict instance to represent a JWS object.
Interface for JWS algorithm. JWA specification (RFC7518) SHOULD implement the algorithms for JWS with this base implementation.
Prepare key for signing and verifying signature.
Sign the text msg with a private/sign key.
msg – message bytes to be signed
key – private key to sign the message
bytes
Verify the signature of text msg with a public/verify key.
msg – message bytes to be signed
sig – result signature to be compared
key – public key to verify the signature
boolean