Pre-release
This release is a pre-release and may not be stable for production use.
Swarmauri Crypto JWE
JSON Web Encryption (JWE) provider implementing RFC 7516 and RFC 7518 compliant encryption and decryption helpers.
Features
- Asynchronous API for compact JWE serialization returning strings.
- Accepts
JWAAlgenums fromswarmauri_core.crypto.typesfor algorithms. - Supports
dir,RSA-OAEP,RSA-OAEP-256, andECDH-ESkey management algorithms. - Supports
A128GCM,A192GCM, andA256GCMcontent encryption. - Optional compression (
zip=DEF) and Additional Authenticated Data (AAD). - Returns structured decrypt results that include both the protected header and plaintext.
- Registers with the Swarmauri PluginManager via the
swarmauri.cryptosentry point.
Installation
pip install swarmauri_crypto_jwe
# or
poetry add swarmauri_crypto_jwe
# or, with uv
uv add 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_core.crypto.types import JWAAlg
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=JWAAlg.RSA_OAEP_256,
enc=JWAAlg.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())
Loading via PluginManager
from swarmauri.plugin import PluginManager
pm = PluginManager()
crypto = pm.load("swarmauri.cryptos", "JweCrypto")
Parameters
alg?JWAAlgmember describing the key management algorithm (JWAAlg.RSA_OAEP_256,JWAAlg.DIR, etc.).enc?JWAAlgmember describing the content encryption algorithm (JWAAlg.A256GCM,JWAAlg.A128GCM, etc.).key? mapping containing the key material used for encryption:{"k": bytes}for direct symmetric keys (dir).{"pub": rsa_public_key}for RSA OAEP, where the public key may be PEM bytes or anRSAPublicKeyinstance.{"pub": ec_public_key}for ECDH-ES with PEM, JWK, or key objects.
- Optional
header_extravalues are merged into the protected header (usezip="DEF"to enable compression). - Decryption requires the matching private key via
dir_key,rsa_private_pem/rsa_private_password, orecdh_private_key. expected_algsandexpected_encsconstrain acceptable algorithms during decryption, andaadmust match the authenticated data provided at encryption time.
Entry point
The provider is registered under the swarmauri.cryptos entry point as JweCrypto.
Want to help?
If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.
Metadata
Release files for swarmauri_crypto_jwe 0.11.0.dev2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| swarmauri_crypto_jwe-0.11.0.dev2.tar.gz | 11.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| swarmauri_crypto_jwe-0.11.0.dev2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.1 kB
Release files / swarmauri_crypto_jwe-0.11.0.dev2.tar.gz
| Download URL | swarmauri_crypto_jwe-0.11.0.dev2.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db5696cefd23db57233f822e103a0be3eb9f74a0eddcdc31d7ccfa2449ee319d
|
|
BLAKE2b-256 checksum How to use checksums |
e8643ef14b96cb5f7d726143e4704bd17d613a90df2e20d68f56d5e3b1f1c6f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / swarmauri_crypto_jwe-0.11.0.dev2-py3-none-any.whl
| Download URL | swarmauri_crypto_jwe-0.11.0.dev2-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
352c005989b432ba3de75e35062fc766703f41743625dfe38ff96fbd8ca589ad
|
|
BLAKE2b-256 checksum How to use checksums |
6498c9bd0c6621ce93d43d3e2d3ee31b903656ff25d14e6ee6058a92f7ba0657
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|