Skip to main content

ABDM ECDH encryption/decryption for secure health data exchange

Project description

abdm-ecdh

CI — Python

Python library implementing the ABDM (Ayushman Bharat Digital Mission) ECDH encryption protocol for secure health data exchange.

Installation

pip install abdm-ecdh==1.0.0

Usage

from abdm_ecdh import generate_key_material, encrypt, decrypt

# Each party generates their own key material
sender    = generate_key_material()
requester = generate_key_material()

# Sender encrypts
enc = encrypt(
    string_to_encrypt="sensitive health data",
    sender_nonce=sender.nonce,
    requester_nonce=requester.nonce,
    sender_private_key=sender.private_key,
    requester_public_key=requester.x509_public_key,
)

# Requester decrypts
dec = decrypt(
    encrypted_data=enc.encrypted_data,
    sender_nonce=sender.nonce,
    requester_nonce=requester.nonce,
    requester_private_key=requester.private_key,
    sender_public_key=sender.x509_public_key,
)

print(dec.decrypted_data)  # "sensitive health data"

API

generate_key_material() -> KeyMaterial

Generates an ECDH key pair on Curve25519 (Weierstrass form) and a random 32-byte nonce.

Returns a KeyMaterial dataclass with fields:

  • private_key — base64-encoded private scalar
  • public_key — base64-encoded uncompressed EC point (65 bytes)
  • x509_public_key — base64-encoded X.509 SubjectPublicKeyInfo DER
  • nonce — base64-encoded 32-byte random nonce

encrypt(...) -> EncryptionResponse

Encrypts a plaintext string using ECDH shared secret derivation + HKDF-SHA256 + AES-256-GCM.

Parameters: string_to_encrypt, sender_nonce, requester_nonce, sender_private_key, requester_public_key

Returns EncryptionResponse with encrypted_data (base64 string).

decrypt(...) -> DecryptionResponse

Decrypts ciphertext using ECDH shared secret derivation + HKDF-SHA256 + AES-256-GCM.

Parameters: encrypted_data, sender_nonce, requester_nonce, requester_private_key, sender_public_key

Returns DecryptionResponse with decrypted_data (string).

Cryptographic Details

  • Key Agreement: ECDH on Curve25519 (Weierstrass form), compatible with Java/BouncyCastle
  • Key Derivation: HKDF-SHA256
  • Encryption: AES-256-GCM
  • Nonce Handling: IV and salt derived from XOR of sender and requester nonces

License

MIT

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

abdm_ecdh-1.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

abdm_ecdh-1.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file abdm_ecdh-1.1.0.tar.gz.

File metadata

  • Download URL: abdm_ecdh-1.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1

File hashes

Hashes for abdm_ecdh-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f47152dc35bfa6472618899094a1c0171ec12e5e2024c0e2f9a58e6b724c2bdf
MD5 09721d9a29cf3613a3fb5c7a4b2da071
BLAKE2b-256 51268d0ae966f8e61879e8f202820343089f6e87c484670a005d278731e1f83a

See more details on using hashes here.

File details

Details for the file abdm_ecdh-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: abdm_ecdh-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1

File hashes

Hashes for abdm_ecdh-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6fb003ffd168d33f23bc801d67b21b41d5d59473f48168641783a9389518a8a9
MD5 a0ac9cbd29e1dbba5b0733b552c2501f
BLAKE2b-256 0f5140dc9bd2c17939e0fe4979b894f069e4dbf90092eb749b1844fc0d04a1ed

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