Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

secure-encryption

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

secure-encryption

A simple and secure encryption service for Python.

  • 0.0.1
  • PyPI
  • Socket score

Maintainers
1
# 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.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc