Skip to main content

A simple and secure encryption service for Python.

Project description

# Secure Encryption

A simple and secure encryption service for Python.

## Features

- AES-256-CTR encryption and decryption
- HMAC-SHA512 message authentication
- Secure environment variable handling for encryption and MAC keys

## Installation

Install the package using pip:

```bash
pip install secure-encryption

Usage

Setting Up Environment Variables

Before using the CryptoService, you need to set up environment variables for the encryption and MAC keys. These keys should be base64 encoded 32-byte keys (for AES-256).

import os
import base64

# Generate random keys and encode them in base64
encryption_key = base64.b64encode(os.urandom(32)).decode('utf-8')
mac_key = base64.b64encode(os.urandom(32)).decode('utf-8')

# Set environment variables
os.environ['CRYPTO_SERVICE_KEY'] = encryption_key
os.environ['CRYPTO_SERVICE_MAC_KEY'] = mac_key

Encrypting a Message

To encrypt a plaintext message:

from secure_encryption.crypto_service import CryptoService

plaintext = "This is a secret message."
encrypted_message = CryptoService.encrypt(plaintext)
print(f"Encrypted: {encrypted_message}")

Decrypting a Message

To decrypt an encrypted message:

from secure_encryption.crypto_service import CryptoService

decrypted_message = CryptoService.decrypt(encrypted_message)
print(f"Decrypted: {decrypted_message}")

Example

import os
import base64
from secure_encryption.crypto_service import CryptoService

# Generate and set keys
encryption_key = base64.b64encode(os.urandom(32)).decode('utf-8')
mac_key = base64.b64encode(os.urandom(32)).decode('utf-8')

os.environ['CRYPTO_SERVICE_KEY'] = encryption_key
os.environ['CRYPTO_SERVICE_MAC_KEY'] = mac_key

# Encrypt a message
plaintext = "This is a secret message."
encrypted_message = CryptoService.encrypt(plaintext)
print(f"Encrypted: {encrypted_message}")

# Decrypt the message
decrypted_message = CryptoService.decrypt(encrypted_message)
print(f"Decrypted: {decrypted_message}")

Running Tests

Unit tests are provided using the unittest framework. To run the tests, use the following command:

python -m unittest discover tests

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.


This README file covers the basic usage, setup, and additional information about your `secure-encryption` package.

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

secure_encryption-0.0.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

secure_encryption-0.0.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file secure_encryption-0.0.1.tar.gz.

File metadata

  • Download URL: secure_encryption-0.0.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for secure_encryption-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bfdea5df847776cb33b2e3f4b8c369940f82ced48b06d0cdb1b058f307893b49
MD5 54c0012812e2985000617d5238c2e8fc
BLAKE2b-256 5e90303018c96236e2e991fbe630e852dc25e3737aebce7a50690223957cc6a9

See more details on using hashes here.

File details

Details for the file secure_encryption-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for secure_encryption-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 87ff84d15fcf4bfbd0f6eb0503a19cfcb3ce10ddc388d2228fe59012a420b6ab
MD5 31408b7f673b0ebb2bc0d92ce36f733e
BLAKE2b-256 d96e54b8d05a1d23e5943427caaf2c439e39e2273dc0c8f65bab5a8007922114

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page