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.dev3.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.dev3.tar.gz.

File metadata

File hashes

Hashes for swarmauri_mre_crypto_keyring-0.3.0.dev3.tar.gz
Algorithm Hash digest
SHA256 154f6f089dea10811aac11ab7680728e079485172135af8b2b56910e587e004a
MD5 54250d83ca2df9e17f0573f6ec374bdc
BLAKE2b-256 a675f6cc32f6520b37aa455d9d810921a94fec163cb2c9da3c2d6a02ff1a24c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swarmauri_mre_crypto_keyring-0.3.0.dev3-py3-none-any.whl
Algorithm Hash digest
SHA256 2c95936ffe5e4ac968de5f316d357bec8dfee582f0056d7ec6b9de073e1fa89b
MD5 eaa949961a28881d3d2cad484ea4a19e
BLAKE2b-256 eb673f71be9210a520a85e4e8b776449a66bb6bc3806ff0960eae5a4b1c8fde8

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