Skip to main content

RFC 7516/7518 compliant JWE crypto provider for Swarmauri

Project description

Swamauri Logo

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


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, and ECDH-ES
  • Supports A128GCM, A192GCM, and A256GCM
  • 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:

  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_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 as RSA-OAEP-256 or dir.
  • enc – content encryption algorithm like A256GCM.
  • key – mapping containing the public key or direct symmetric key material.
  • Decryption requires the matching private key via rsa_private_pem, dir_key, or ecdh_private_key.

Entry point

The provider is registered under the swarmauri.cryptos entry point as JweCrypto.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_crypto_jwe-0.2.0.dev3.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swarmauri_crypto_jwe-0.2.0.dev3-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_crypto_jwe-0.2.0.dev3.tar.gz.

File metadata

File hashes

Hashes for swarmauri_crypto_jwe-0.2.0.dev3.tar.gz
Algorithm Hash digest
SHA256 b9ad8acedb2fd5e67130cbfc039e842f82b5db652a506f42390fa5090c25fc26
MD5 08c1c64ae9e398843310725f3dbaf470
BLAKE2b-256 1c3e6997a0715522a99c60f03eac7b305e3a910d4283835a492f3dd4c70ad696

See more details on using hashes here.

File details

Details for the file swarmauri_crypto_jwe-0.2.0.dev3-py3-none-any.whl.

File metadata

File hashes

Hashes for swarmauri_crypto_jwe-0.2.0.dev3-py3-none-any.whl
Algorithm Hash digest
SHA256 ffc316db6007541d3061fa015177b4b581a7d96794a2fe35db504e9ac62a94e8
MD5 06134dd0e4fab528fc17b37ecffd1633
BLAKE2b-256 2105c80e2189af570ae7f27aa5c386d1cf21fc82cf0a80ba802e1b2ba1d36a0d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page