Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_crypto_jwe Discord

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 JWAAlg enums from swarmauri_core.crypto.types for algorithms.
  • Supports dir, RSA-OAEP, RSA-OAEP-256, and ECDH-ES key management algorithms.
  • Supports A128GCM, A192GCM, and A256GCM content 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.cryptos entry 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:

  1. Generate or load the key material for the chosen algorithm.
  2. Instantiate JweCrypto.
  3. Call encrypt_compact with the payload, algorithm, and key details.
  4. Call decrypt_compact with 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 ? JWAAlg member describing the key management algorithm (JWAAlg.RSA_OAEP_256, JWAAlg.DIR, etc.).
  • enc ? JWAAlg member 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 an RSAPublicKey instance.
    • {"pub": ec_public_key} for ECDH-ES with PEM, JWK, or key objects.
  • Optional header_extra values are merged into the protected header (use zip="DEF" to enable compression).
  • Decryption requires the matching private key via dir_key, rsa_private_pem/rsa_private_password, or ecdh_private_key.
  • expected_algs and expected_encs constrain acceptable algorithms during decryption, and aad must match the authenticated data provided at encryption time.

Opt-in X448

Use JweCrypto(enable_x448=True) with alg=JWAAlg.ECDH_ES, enc=JWAAlg.A256GCM, and a public recipient JWK with kty="OKP", crv="X448", and a base64url-encoded x. Pass an X448PrivateKey as ecdh_private_key to decrypt.

New ECDH-ES tokens use the RFC 7518 Concat KDF. To read X25519 or NIST-curve tokens issued with the previous Swarmauri KDF, pass legacy_ecdh_kdf=True to decrypt_compact for those known tokens.

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.dev4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for swarmauri_crypto_jwe 0.11.0.dev4
File Size Uploaded Provenance Actions
swarmauri_crypto_jwe-0.11.0.dev4.tar.gz 14.3 kB Without provenance Details for swarmauri_crypto_jwe-0.11.0.dev4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for swarmauri_crypto_jwe 0.11.0.dev4
File Interpreter ABI Platform Actions
swarmauri_crypto_jwe-0.11.0.dev4-py3-none-any.whl Python 3 none any Details for swarmauri_crypto_jwe-0.11.0.dev4-py3-none-any.whl

Total release size: 27.8 kB

Release files / swarmauri_crypto_jwe-0.11.0.dev4.tar.gz

Download URL swarmauri_crypto_jwe-0.11.0.dev4.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
00e4ec3589d022ef99666014cec230f146b034550a8714b12ec22b8d75b7c67f
BLAKE2b-256 checksum
How to use checksums
39dd470b860c09bc3b2925aba2910cc933ffe53bf81d9956b2395a0ec460a914
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.dev4-py3-none-any.whl

Download URL swarmauri_crypto_jwe-0.11.0.dev4-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01a6fdeeeeae1044c89c85cf0141a357718bb401bc567d1316d9acb60637582e
BLAKE2b-256 checksum
How to use checksums
9602a3ebe76190b8beea51adfd6d1b4a1dd48ca60c17aac4d829b8763511150c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for swarmauri_crypto_jwe 0.11.0.dev4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page