Skip to main content

Python library for encryption use in PyEQX ecosystem.

Project description

esbm-pyeqx-encryption

An encryption library for using in pyeqx ecosystem.

Currently support encryption features:

  • Kyber512 - Key Encapsulation Mechanism - KEM
  • HKDF-SHA256 - HKDF-SHA256 (HMAC-based Key Derivation Function)
  • AES 256 GCM - AES-256-GCM (Advanced Encryption Standard with Galois/Counter Mode)

status: in development

Installation

This is an instruction to prepare your local machine to use and/or develop this library.

Pre-requisites

To setup virtual environment to execute unit tests, it has to setup virtual env and install dependencies

# setup virtual env
python3.12 -m venv .venv

# activate virtual env
source .venv/bin/activate

To setup vscode, run yarn install which will setup and configure the vscode to support formatting, linting, and etc.

#
yarn install

Project Structure

pyeqx-encryption-cli/
├── src/
│ └── pyeqx/
│ └── encryption/ # The actual Python package
│ ├── **init**.py # Defines the package and exposes core functions
│ ├── cli.py # Command-line interface logic
│ └── core.py # Core cryptographic functions (Kyber, HKDF, AES)
├── test/ # Unit tests for the core logic
│ └── pyeqx/
│ └── encryption/ # The actual Python package
│ ├── test_core.py
│ └── test_cli_keygen.py
├── .gitignore # Specifies files/directories to ignore by Git
├── LICENSE # Licensing information (e.g., MIT)
├── pyproject.toml # Modern project metadata, dependencies, and build configuration
├── README.md # Project overview, installation, and usage instructions
└── requirements.txt # Development dependencies

Usage

Development

to execute unit test run this command at root of the project

pytest -s

Build

to build the package run this command at root of the project

python3 -m pip install --upgrade build
python3 -m build

CLI

First, execute this command pip3 install -e . to install current as python binary.

To generate key-pair, execute following command

pyeqx-encryption-cli keygen --public-out .tmp/alice_public.key --private-out .tmp/alice_private.key

To encapsulate Alice public key for Bob to send cipher_text and salt to Alice

pyeqx-encryption-cli encapsulate \
  --public-in .tmp/alice_public.key \
  --ciphertext-out .tmp/bob_kyber_ciphertext.bin \
  --shared-secret-out .tmp/bob_secret.bin \
  --aes-key-out .tmp/bob_aes_key.bin \
  --salt-out .tmp/bob_aes_salt.bin

To decapsulate cipher_text and salt from Bob

pyeqx-encryption-cli decapsulate --private-in .tmp/alice_private.key \
  --ciphertext-in .tmp/bob_kyber_ciphertext.bin \
  --salt-in .tmp/bob_aes_salt.bin \
  --shared-secret-out .tmp/alice_recovered_secret.bin \
  --aes-key-out .tmp/alice_aes_key.bin

To verify both aes key are identical, just hexdump, it should be identical

hexdump -C alice_aes_key.bin
hexdump -C bob_aes_key.bin

To encrypt the file

pyeqx-encryption-cli encrypt-file --aes-key-in .tmp/alice_aes_key.bin \
  --input .tmp/secret_document.txt \
  --output-ciphertext .tmp/encrypted_message.bin \
  --output-nonce .tmp/message_nonce.bin \
  --output-tag .tmp/message_tag.bin \
  --associated-data "Project_Alpha_Report"

To decrypt the file

pyeqx-encryption-cli decrypt-file --aes-key-in .tmp/bob_aes_key.bin \
  --input .tmp/encrypted_message.bin \
  --input-nonce .tmp/message_nonce.bin \
  --input-tag .tmp/message_tag.bin \
  --output .tmp/decrypted_document.txt \
  --associated-data "Project_Alpha_Report"

Scenario

The usage scenario for a 2-party secure file exchange. The scenario is Alice send a secret file to Bob

Please see docs/scenario.md

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

pyeqx_encryption-0.2.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

pyeqx_encryption-0.2.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file pyeqx_encryption-0.2.0.tar.gz.

File metadata

  • Download URL: pyeqx_encryption-0.2.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for pyeqx_encryption-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b24369759eca046cb2cd20d243891876d4e2479f476df847524e18e79ac456d9
MD5 5d32ba3823f75c1855965fd725f21ab3
BLAKE2b-256 934d29b955ed2ad31e823a221d41af858bb7ecd05d6dc135a5db154194b1fd2f

See more details on using hashes here.

File details

Details for the file pyeqx_encryption-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyeqx_encryption-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70b9565407caae416e85dc6a5ffca8b4eaefb25ce07afd88c7eb2ac2aa64c4ad
MD5 aef40a81357c84dc61c1ec31ca9046d0
BLAKE2b-256 8a93e260c9b8eb16bd701049fc3befb59a13f8f4b2d375b6aa7844fc257dd230

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