RFC 7516/7518 compliant JWE crypto provider for Swarmauri
Project description
Swarmauri Crypto JWE
JSON Web Encryption (JWE) provider implementing RFC 7516 and RFC 7518 compliant encryption and decryption helpers.
- Supports
dir,RSA-OAEP,RSA-OAEP-256, andECDH-ES - Supports
A128GCM,A192GCM, andA256GCM - Optional compression (
zip=DEF) and Additional Authenticated Data (AAD)
Installation
pip install swarmauri_crypto_jwe
Usage
The helpers are asynchronous and return compact JWE strings that can be decrypted back into their original plaintext. A typical flow is:
- Generate or load the key material for the chosen algorithm.
- Instantiate
JweCrypto. - Call
encrypt_compactwith the payload, algorithm, and key details. - Call
decrypt_compactwith the resulting JWE and the corresponding private key.
import asyncio
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from swarmauri_crypto_jwe import JweCrypto
async def main() -> None:
crypto = JweCrypto()
sk = rsa.generate_private_key(public_exponent=65537, key_size=2048)
pk_pem = sk.public_key().public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo,
)
jwe = await crypto.encrypt_compact(
payload=b"secret",
alg="RSA-OAEP-256",
enc="A256GCM",
key={"pub": pk_pem},
)
result = await crypto.decrypt_compact(
jwe,
rsa_private_pem=sk.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption(),
),
)
assert result.plaintext == b"secret"
asyncio.run(main())
Parameters
alg– key management algorithm such asRSA-OAEP-256ordir.enc– content encryption algorithm likeA256GCM.key– mapping containing the public key or direct symmetric key material.- Decryption requires the matching private key via
rsa_private_pem,dir_key, orecdh_private_key.
Entry point
The provider is registered under the swarmauri.cryptos entry point as JweCrypto.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarmauri_crypto_jwe-0.2.0.dev4.tar.gz.
File metadata
- Download URL: swarmauri_crypto_jwe-0.2.0.dev4.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b7d61372d4b6840e234798f39a37f54c020b9f60eed1f54ae3fe4dcdd3d4d63
|
|
| MD5 |
d33fb957bb24024fa8a8ec124a6d3b51
|
|
| BLAKE2b-256 |
d8ab8aeb2e469ac1e589779d33e3786e924f005970080081dd3acea38e4172ab
|
File details
Details for the file swarmauri_crypto_jwe-0.2.0.dev4-py3-none-any.whl.
File metadata
- Download URL: swarmauri_crypto_jwe-0.2.0.dev4-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef67bb30caded223faa44c7708fb772fcd031459b965f8cbfa404b0e20f42f07
|
|
| MD5 |
715ebe68ddcffe9be47f250ca0fd6e98
|
|
| BLAKE2b-256 |
361580e2645c35e8e4bd96d1934b62aaa7bf06cb3c829ca44de56b6fe5e349bd
|