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.dev4.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.dev4-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for swarmauri_crypto_jwe-0.2.0.dev4.tar.gz
Algorithm Hash digest
SHA256 8b7d61372d4b6840e234798f39a37f54c020b9f60eed1f54ae3fe4dcdd3d4d63
MD5 d33fb957bb24024fa8a8ec124a6d3b51
BLAKE2b-256 d8ab8aeb2e469ac1e589779d33e3786e924f005970080081dd3acea38e4172ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swarmauri_crypto_jwe-0.2.0.dev4-py3-none-any.whl
Algorithm Hash digest
SHA256 ef67bb30caded223faa44c7708fb772fcd031459b965f8cbfa404b0e20f42f07
MD5 715ebe68ddcffe9be47f250ca0fd6e98
BLAKE2b-256 361580e2645c35e8e4bd96d1934b62aaa7bf06cb3c829ca44de56b6fe5e349bd

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