Skip to main content

Keyring-backed multi-recipient encryption provider for Swarmauri

Project description

Swamauri Logo

Swarmauri MRE Crypto Keyring

Multi-recipient encryption provider using external keyrings/HSMs.

Installation

pip install swarmauri_mre_crypto_keyring

Usage

KeyringMreCrypto delegates CEK (content-encryption key) management to user-provided keyring clients. Each client must implement id, wrap_cek, and unwrap_cek. The example below shows how to register an in-memory keyring and use it to encrypt and decrypt a payload.

import asyncio
import secrets
from swarmauri_mre_crypto_keyring import KeyringMreCrypto


class MemoryKeyring:
    def __init__(self):
        self._store = {}

    def id(self) -> str:
        return "memory"

    async def wrap_cek(self, cek: bytes, *, context):
        token = secrets.token_bytes(8)
        self._store[token] = cek
        return token

    async def unwrap_cek(self, header: bytes, *, context):
        return self._store[header]


async def main():
    keyring = MemoryKeyring()
    keyref = {"kind": "keyring_client", "client": keyring}
    crypto = KeyringMreCrypto()
    env = await crypto.encrypt_for_many([keyref], b"sensitive data")
    recovered = await crypto.open_for(keyref, env)
    assert recovered == b"sensitive data"


asyncio.run(main())

The snippet encrypts b"sensitive data" for the memory keyring and recovers the original plaintext using the same keyring client.

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_mre_crypto_keyring-0.3.0.dev4.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file swarmauri_mre_crypto_keyring-0.3.0.dev4.tar.gz.

File metadata

File hashes

Hashes for swarmauri_mre_crypto_keyring-0.3.0.dev4.tar.gz
Algorithm Hash digest
SHA256 b9bcf838d7dc4a55a3a022cd97815595261c63dd44e4a6dd7a6468fde8119b5e
MD5 a2f3750b24aa65cf7841b693862daddb
BLAKE2b-256 96862b1b9cec2a728b891faf13edbb4fcfb339faf473010a5a59b6ef78f058fe

See more details on using hashes here.

File details

Details for the file swarmauri_mre_crypto_keyring-0.3.0.dev4-py3-none-any.whl.

File metadata

File hashes

Hashes for swarmauri_mre_crypto_keyring-0.3.0.dev4-py3-none-any.whl
Algorithm Hash digest
SHA256 382d0c27157648ebbb41f681228959d9c10135297606150ce7bf0f3faae39461
MD5 14c0cb9825c8f9ff8f18f5806ca4e847
BLAKE2b-256 422e99d04c5bedc998eb03f561c85a9b4e0ca0c70b3910d10c2903b179ec7122

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