Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
sign
✓ from jose import sign
✗ from jose import sign
This quickstart demonstrates basic JWS signing/verification and JWE encryption/decryption using the `jose` library (Demonware). It illustrates how to define headers, use RSA keys (generated for demonstration), and call the core `sign`, `verify`, `encrypt`, and `decrypt` functions. Note the explicit requirement for `pycrypto` and the caveats regarding its suitability for modern, secure applications.
import jose
from time import time
# NOTE: For modern Python and security, consider `pip install python-jose[cryptography]` instead.
# This example is for the *Demonware jose* library, which uses the deprecated `pycrypto`.
# Ensure `pycrypto` is installed (e.g., `pip install pycrypto==2.6.1`)
# For generating RSA keys safely, a more robust library like `cryptography` or `PyCryptodome`
# would be used in a real application, not the raw `Crypto.PublicKey.RSA` as it relies on pycrypto.
try:
from Crypto.PublicKey import RSA
except ImportError:
print("Error: `pycrypto` not found. Please install it (pip install pycrypto==2.6.1).")
# Exit or handle error gracefully in a real script
exit(1)
# Generate a new RSA key pair for demonstration purposes
# In a real app, you would load pre-existing keys securely.
key = RSA.generate(2048) # Generates an RSA key with 2048 bits
claims = {
'iss': 'http://www.example.com',
'exp': int(time() + 3600), # Expiration time (1 hour from now)
'aud': 'http://www.example.org',
'sub': 'testuser',
'nbf': int(time()) # Not Before time
}
# --- JWS (JSON Web Signature) Example ---
# Define JWS Protected Header
protected_jws_header = {
'alg': 'RS256' # RSA Signature with SHA-256
}
try:
# Sign the claims with the private key
signed_jws = jose.sign(protected_jws_header, claims, key)
print("Signed JWS:", signed_jws)
# Verify the JWS with the public key
verified_claims = jose.verify(signed_jws, key.publickey())
print("Verified JWS Claims:", verified_claims)
# --- JWE (JSON Web Encryption) Example ---
# Define JWE Protected Header
protected_jwe_header = {
'alg': 'RSA-OAEP', # Algorithm for Content Encryption Key (CEK) encryption
'enc': 'A128CBC-HS256' # Algorithm for content encryption
}
# Encrypt the claims with the recipient's public key
encrypted_jwe = jose.encrypt(protected_jwe_header, claims, key.publickey())
print("Encrypted JWE:", encrypted_jwe)
# Decrypt the JWE with the recipient's private key
decrypted_jwe_payload = jose.decrypt(encrypted_jwe, key)
print("Decrypted JWE Payload:", decrypted_jwe_payload)
except jose.Error as e:
print(f"JOSE Error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Upgrade
Version history
1.0.0latest on PyPI · released Nov 13, 2015
Audit
Dependencies
pycryptorequiredCore cryptographic operations. This library is deprecated and has known security vulnerabilities, making `jose` unsuitable for secure applications.