Skip to main content

OpenPGP (GnuPG) + AES-GCM crypto provider for Swarmauri

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_crypto_pgp


Swarmauri Crypto PGP

PGPCrypto is an OpenPGP (GnuPG-backed) crypto provider that implements the ICrypto contract from swarmauri_core. It combines modern AEAD primitives with OpenPGP public-key operations so that the same component can handle symmetrical encryption, public-key key wrapping, and hybrid envelopes.

Features at a glance

  • Symmetric AEAD – AES-256-GCM powers encrypt and decrypt.
  • Key wrappingwrap and unwrap delegate to GnuPG to protect random or supplied key material with a recipient's public/private key pair.
  • Hybrid envelopesencrypt_for_many supports both traditional KEM+AEAD (shared ciphertext + wrapped session key) and OpenPGP sealed mode for per-recipient ciphertexts.
  • Sealing convenienceseal and unseal provide single-recipient OpenPGP public-key encryption without managing the envelope structure.

System requirements

  • Python 3.10 – 3.13.
  • GnuPG available on the PATH (required by python-gnupg).

Key material expectations

  • encrypt / decrypt: KeyRef.material must be 16/24/32 bytes for AES-GCM.
  • wrap / encrypt_for_many: KeyRef.public must be ASCII-armored OpenPGP public key bytes.
  • unwrap / unseal: KeyRef.material must be ASCII-armored OpenPGP private key bytes. Supply a passphrase via KeyRef.tags["passphrase"] when needed.

Installation

Choose the tool that matches your workflow:

# pip
pip install swarmauri_crypto_pgp

# Poetry
poetry add swarmauri_crypto_pgp

# uv
uv add swarmauri_crypto_pgp

Quickstart

The snippet below mirrors the asynchronous usage exercised in the tests. It creates a symmetric KeyRef, encrypts plaintext, and decrypts the resulting AEADCiphertext back to bytes.

import asyncio

from swarmauri_crypto_pgp import PGPCrypto
from swarmauri_core.crypto.types import ExportPolicy, KeyRef, KeyType, KeyUse


async def main() -> None:
    crypto = PGPCrypto()

    # Symmetric key for AES-256-GCM
    sym = KeyRef(
        kid="sym1",
        version=1,
        type=KeyType.SYMMETRIC,
        uses=(KeyUse.ENCRYPT, KeyUse.DECRYPT),
        export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
        material=b"\x00" * 32,
    )

    ct = await crypto.encrypt(sym, b"hello OpenPGP")
    pt = await crypto.decrypt(sym, ct)

    print(pt)


if __name__ == "__main__":
    asyncio.run(main())

Working with recipients

  • Call encrypt_for_many with recipient public keys to either produce an AES-GCM ciphertext with OpenPGP-wrapped session keys (default) or per-recipient sealed blobs by passing enc_alg="OpenPGP-SEAL".
  • Use seal / unseal for single-recipient OpenPGP public-key encryption.
  • wrap and unwrap offer direct access to OpenPGP-based key encapsulation.

Entry point

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

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.

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_pgp-0.3.0.dev3.tar.gz (9.6 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_pgp-0.3.0.dev3-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_crypto_pgp-0.3.0.dev3.tar.gz.

File metadata

  • Download URL: swarmauri_crypto_pgp-0.3.0.dev3.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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}

File hashes

Hashes for swarmauri_crypto_pgp-0.3.0.dev3.tar.gz
Algorithm Hash digest
SHA256 f7deeda9040d6f017d8a2b1a46f6d0669f0bf35053453f77979f29d85f9d3acf
MD5 51aa779dac051e7eb8a4982c1f447eb6
BLAKE2b-256 f7f67ac1fdff9cf8943fee05dfade29297158a04aac14032bee2c30cc37d0b0d

See more details on using hashes here.

File details

Details for the file swarmauri_crypto_pgp-0.3.0.dev3-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_crypto_pgp-0.3.0.dev3-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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}

File hashes

Hashes for swarmauri_crypto_pgp-0.3.0.dev3-py3-none-any.whl
Algorithm Hash digest
SHA256 0a52e2c5065499993d3c8b23170b98c7655cdb588d662e665419554161dfc966
MD5 1c3b438f9f1eab548a91c1e5e29197bc
BLAKE2b-256 3e49fc2c71b8fdf5c397cbdc01c7ebf654c5726148ad910b23d3a059ea33b670

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