Skip to main content

Core encryption utilities for python envencrypt

Project description

envencrypt-core

Core encryption utilities for Python envencrypt - A collection of high-performance, secure encryption modules built with Rust and exposed to Python via PyO3.

Overview

envencrypt-core provides platform-specific encryption capabilities for securing sensitive data like environment variables, passwords, and configuration files. The library leverages native OS security features to provide robust encryption with minimal performance overhead.

[!NOTE] Currently only the windows DPAPI is implemented.

Features

  • Windows platform encryption: Support for Windows DPAPI
  • High performance: Rust-based implementation for maximum speed and safety
  • Secure by default: Uses OS-native security APIs and best practices
  • Python integration: Seamless Python bindings with proper type hints
  • Zero-copy operations: Efficient memory handling for large data

Modules

DPAPI (Windows)

Windows Data Protection API integration for secure data encryption:

  • User scope encryption: Data encrypted for current user account
  • Machine scope encryption: Data encrypted for the machine
  • Optional entropy: Additional security layer with custom entropy
  • Automatic key management: No manual key handling required

Installation

pip install envencrypt-core

Note: Platform-specific modules are automatically installed based on your operating system.

Quick Start

DPAPI (Windows only)

from envencrypt_core.dpapi import dpapi_protect, dpapi_unprotect

# Basic encryption (user scope)
data = b"sensitive information"
encrypted = dpapi_protect(data)
decrypted = dpapi_unprotect(encrypted)

# With custom entropy for additional security
entropy = b"custom-entropy-string"
encrypted = dpapi_protect(data, entropy)
decrypted = dpapi_unprotect(encrypted, entropy)

# Machine scope (requires admin privileges)
encrypted = dpapi_protect(data, machine_scope=True)
decrypted = dpapi_unprotect(encrypted)

API Reference

DPAPI Functions

dpapi_protect(data, optional_entropy=None, machine_scope=False)

Encrypts data using Windows DPAPI.

Parameters:

  • data (bytes): Data to encrypt
  • optional_entropy (bytes, optional): Additional entropy for encryption
  • machine_scope (bool, optional): Use machine scope instead of user scope

Returns: bytes - Encrypted data

dpapi_unprotect(data, optional_entropy=None)

Decrypts data encrypted with DPAPI.

Parameters:

  • data (bytes): Encrypted data to decrypt
  • optional_entropy (bytes, optional): Entropy used during encryption

Returns: bytes - Decrypted data

Security Considerations

  • DPAPI: Data is tied to the user account or machine. Encrypted data cannot be decrypted by different users or on different machines (unless using machine scope).
  • Entropy: When using DPAPI with custom entropy, ensure the entropy is stored securely and separately from the encrypted data.

Development

Prerequisites

  • Rust 1.70+
  • Python 3.11+
  • Platform-specific development tools (Windows SDK, Linux development packages)

Building from Source

# Clone the repository
git clone <repository-url>
cd envencrypt-core

# Build all modules
./build_all.ps1

# Or build individual modules
cd crates/dpapi && cargo build --release
cd crates/keyring && cargo build --release

Testing

# Run Rust tests
cargo test

# Run Python integration tests
python -m pytest tests/

Platform Support

Platform DPAPI Keyring
Windows 🚧
macOS 🚧
Linux 🚧

License

This project is licensed under the GPL-3.0-or-later License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please ensure all tests pass and follow the existing code style.

Authors

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

envencrypt_core-0.2.0.tar.gz (24.1 kB view details)

Uploaded Source

Built Distributions

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

envencrypt_core-0.2.0-cp39-abi3-win_amd64.whl (114.8 kB view details)

Uploaded CPython 3.9+Windows x86-64

envencrypt_core-0.2.0-cp39-abi3-win32.whl (108.8 kB view details)

Uploaded CPython 3.9+Windows x86

File details

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

File metadata

  • Download URL: envencrypt_core-0.2.0.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for envencrypt_core-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0f985ae7e7dd7f19e883666712c69674a5c89f641cb01a23f181bb5e1cf277ba
MD5 469525cf3d69eb039bebe4966181ade4
BLAKE2b-256 198451367ae5c14081beac4a3525d57cffbe190e8ad0ea31f3b5c6de122ad05c

See more details on using hashes here.

File details

Details for the file envencrypt_core-0.2.0-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for envencrypt_core-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b69b665932996a5da41e0851d6298470ec6499938e5456baa998ba8daafa0ba3
MD5 56da9ef6156a45ca52ac109a3331c1e0
BLAKE2b-256 c3b95e4bfe84e212773aaf4657c5edfafa3ec2e4f8ea928925e40ca0f6d77281

See more details on using hashes here.

File details

Details for the file envencrypt_core-0.2.0-cp39-abi3-win32.whl.

File metadata

File hashes

Hashes for envencrypt_core-0.2.0-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 4d594c8cf860deb29f75bd612b2e6dfe6cba000158102d0b8b9ea9bf8829b7ea
MD5 05b24705526c3c2ed30dace7c91cbf64
BLAKE2b-256 94870d61df5d2c64de2081d12752a857ac016e6051f3ba32a31a9eb248169e82

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