Skip to main content

Paramiko-backed RSA + AES-GCM crypto provider for Swarmauri

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_crypto_paramiko


Swarmauri Crypto Paramiko

Paramiko-backed crypto provider implementing the ICrypto contract via CryptoBase. Built on top of paramiko and cryptography, it exposes an asynchronous API for several cryptographic primitives using OpenSSH-formatted public keys and PEM-encoded private keys supplied through KeyRef objects.

Features

  • AES-256-GCM symmetric encrypt/decrypt (16/24/32 byte keys)
  • RSA-OAEP(SHA-256) wrap/unwrap for OpenSSH RSA key pairs
  • AES-256-GCM key wrap/unwrap when the KEK is symmetric
  • RSA-OAEP(SHA-256) sealing for small payloads
  • Multi-recipient hybrid envelopes using OpenSSH public keys

Keys are represented by KeyRef objects. Public keys should be provided in OpenSSH format via KeyRef.public, while private keys are supplied as PEM-encoded bytes in KeyRef.material. RSA sealing is limited to inputs no larger than the modulus-dependent RSA-OAEP bound (`modulus_bytes - 2 * hash_len

  • 2`). For larger payloads use the hybrid envelope mode instead.

Installation

Choose the tool that matches your workflow:

# pip
pip install swarmauri_crypto_paramiko

# Poetry
poetry add swarmauri_crypto_paramiko

# uv
uv add swarmauri_crypto_paramiko

Usage

Symmetric AEAD Encryption

from swarmauri_crypto_paramiko import ParamikoCrypto
from swarmauri_core.crypto.types import KeyRef, KeyType, KeyUse, ExportPolicy

crypto = ParamikoCrypto()

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")
pt = await crypto.decrypt(sym, ct)

RSA Key Wrapping/Unwrapping

import paramiko
from cryptography.hazmat.primitives import serialization
from swarmauri_core.crypto.types import KeyRef, KeyType, KeyUse, ExportPolicy

crypto = ParamikoCrypto()

key = paramiko.RSAKey.generate(2048)
pub_line = f"{key.get_name()} {key.get_base64()}\n".encode()
priv_pem = key.key.private_bytes(
    encoding=serialization.Encoding.PEM,
    format=serialization.PrivateFormat.PKCS8,
    encryption_algorithm=serialization.NoEncryption(),
)

recipient = KeyRef(
    kid="rsa1",
    version=1,
    type=KeyType.RSA,
    uses=(KeyUse.WRAP, KeyUse.UNWRAP),
    export_policy=ExportPolicy.PUBLIC_ONLY,
    public=pub_line,
    material=priv_pem,
)

wrapped = await crypto.wrap(recipient)
unwrapped = await crypto.unwrap(recipient, wrapped)

To wrap with a symmetric key-encryption key instead, provide the AES key bytes in KeyRef.material and set wrap_alg="AES-256-GCM":

sym_kek = KeyRef(
    kid="kek1",
    version=1,
    type=KeyType.SYMMETRIC,
    uses=(KeyUse.WRAP, KeyUse.UNWRAP),
    export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
    material=b"\x01" * 32,
)

wrapped = await crypto.wrap(sym_kek, wrap_alg="AES-256-GCM")
plaintext_key = await crypto.unwrap(sym_kek, wrapped)

RSA Sealing for Small Payloads

# Using the `recipient` defined above
sealed = await crypto.seal(recipient, b"tiny secret")
plaintext = await crypto.unseal(recipient, sealed)

Hybrid Envelope for Multiple Recipients

env = await crypto.encrypt_for_many([recipient], b"secret")

Calling encrypt_for_many without overrides produces an AES-256-GCM ciphertext shared by every recipient, while env.recipients holds RSA-OAEP-wrapped session keys. Use enc_alg="RSA-OAEP-SHA256-SEAL" to emit individual RSA-OAEP sealed payloads instead of a shared ciphertext when the plaintext fits within the sealing size limit.

Entry point

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

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_paramiko-0.3.0.dev33.tar.gz (10.8 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_paramiko-0.3.0.dev33-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_crypto_paramiko-0.3.0.dev33.tar.gz.

File metadata

  • Download URL: swarmauri_crypto_paramiko-0.3.0.dev33.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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_paramiko-0.3.0.dev33.tar.gz
Algorithm Hash digest
SHA256 2cc44a840e60299e25c0f29831208c2afc92ddffbe2b84a08cd8dc283975fd69
MD5 96f457330f682d62fce012e5e0624261
BLAKE2b-256 2cf3fa297eadd9b7a31ebbd6f435badc2c7db87258c1110661d628ad4f99a4c8

See more details on using hashes here.

File details

Details for the file swarmauri_crypto_paramiko-0.3.0.dev33-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_crypto_paramiko-0.3.0.dev33-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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_paramiko-0.3.0.dev33-py3-none-any.whl
Algorithm Hash digest
SHA256 caf48be90b57ab723794d1f9b18f24f23e9db37d95bb9f61ba7629303794a14e
MD5 9680bd30e43d7d6bb6f22b12fc1fe0b0
BLAKE2b-256 c24cf86156e9ce3313dacfac7a0011ad8047841ff8b3504454f16f7ed5e1869a

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