Skip to main content

A comprehensive Python library for secure encryption, hashing, communication, and asymmetric encryption.

Project description

Secupy Library

Overview

Secupy is a Python-based library designed for secure encryption, hashing, communication, and asymmetric encryption operations. It helps developers integrate security features such as message signing, password hashing, encryption/decryption, and asymmetric encryption into their applications seamlessly.

This library provides a simple and efficient way to handle various security tasks, making it ideal for use in applications that require data protection and secure communications.


Modules

  1. Encryptor: Symmetric Encryption and Decryption using the Fernet algorithm.
  2. Hasher: Secure hashing of passwords using bcrypt.
  3. SecureCommunicator: Message signing and verification using HMAC.
  4. AsymmetricEncryptor: Asymmetric encryption and decryption using RSA.
  5. KeyManager: Generates cryptographic keys using PBKDF2 with a given password.

Installation

To install Secupy, simply clone the repository and install the required dependencies.

git clone https://github.com/ChAbdulWahhab/Secupy
cd secupy
pip install -r requirements.txt

Usage

Below are examples of how to use each module in both Flask and Django applications.


1. Encryptor: Symmetric Encryption and Decryption

The Encryptor class uses the Fernet encryption method to encrypt and decrypt messages securely.

Flask Example:

from flask import Flask, request, jsonify
from secupy import Encryptor

app = Flask(__name__)

@app.route('/encrypt', methods=['POST'])
def encrypt_message():
    message = request.json.get('message')
    encryptor = Encryptor()
    encrypted = encryptor.encrypt(message)
    decrypted = encryptor.decrypt(encrypted)
    return jsonify({"Encrypted": encrypted, "Decrypted": decrypted})

if __name__ == '__main__':
    app.run(debug=True)

Django Example:

from django.http import JsonResponse
from secupy import Encryptor

def encrypt_message(request):
    message = request.POST.get('message')
    encryptor = Encryptor()
    encrypted = encryptor.encrypt(message)
    decrypted = encryptor.decrypt(encrypted)
    return JsonResponse({"Encrypted": encrypted, "Decrypted": decrypted})

2. Hasher: Password Hashing and Verification

The Hasher class uses bcrypt for securely hashing and verifying passwords.

Flask Example:

from flask import Flask, request, jsonify
from secupy import Hasher

app = Flask(__name__)

@app.route('/hash-password', methods=['POST'])
def hash_password():
    password = request.json.get('password')
    hasher = Hasher()
    hashed_password = hasher.hash_password(password)
    is_valid = hasher.verify_password(password, hashed_password)
    return jsonify({"Hashed Password": hashed_password, "Password Valid": is_valid})

if __name__ == '__main__':
    app.run(debug=True)

Django Example:

from django.http import JsonResponse
from secupy import Hasher

def hash_password(request):
    password = request.POST.get('password')
    hasher = Hasher()
    hashed_password = hasher.hash_password(password)
    is_valid = hasher.verify_password(password, hashed_password)
    return JsonResponse({"Hashed Password": hashed_password, "Password Valid": is_valid})

3. SecureCommunicator: Message Signing and Verification

The SecureCommunicator class uses HMAC with SHA-256 to securely sign messages and verify their authenticity.

Flask Example:

from flask import Flask, request, jsonify
from secupy import SecureCommunicator

app = Flask(__name__)

@app.route('/secure-message', methods=['POST'])
def secure_message():
    message = request.json.get('message')
    secret_key = "your_secret_key"
    communicator = SecureCommunicator(secret_key)
    signature = communicator.generate_signature(message)
    is_valid = communicator.verify_signature(message, signature)
    return jsonify({"Message": message, "Signature Valid": is_valid})

if __name__ == '__main__':
    app.run(debug=True)

Django Example:

from django.http import JsonResponse
from secupy import SecureCommunicator

def secure_message(request):
    message = request.POST.get('message')
    secret_key = "your_secret_key"
    communicator = SecureCommunicator(secret_key)
    signature = communicator.generate_signature(message)
    is_valid = communicator.verify_signature(message, signature)
    return JsonResponse({"Message": message, "Signature Valid": is_valid})

4. AsymmetricEncryptor: Asymmetric Encryption and Decryption

The AsymmetricEncryptor class uses RSA for asymmetric encryption and decryption, allowing secure communication between two parties with private and public keys.

Flask Example:

from flask import Flask, request, jsonify
from secupy import AsymmetricEncryptor

app = Flask(__name__)

@app.route('/asymmetric-encrypt', methods=['POST'])
def asymmetric_encrypt():
    message = request.json.get('message')
    asymmetric = AsymmetricEncryptor()
    encrypted_message = asymmetric.encrypt(message)
    decrypted_message = asymmetric.decrypt(encrypted_message)
    return jsonify({"Encrypted Message": encrypted_message, "Decrypted Message": decrypted_message})

if __name__ == '__main__':
    app.run(debug=True)

Django Example:

from django.http import JsonResponse
from secupy import AsymmetricEncryptor

def asymmetric_encrypt(request):
    message = request.POST.get('message')
    asymmetric = AsymmetricEncryptor()
    encrypted_message = asymmetric.encrypt(message)
    decrypted_message = asymmetric.decrypt(encrypted_message)
    return JsonResponse({"Encrypted Message": encrypted_message, "Decrypted Message": decrypted_message})

5. KeyManager: Key Generation for Encryption

The KeyManager class generates secure cryptographic keys using PBKDF2 with a password.

Flask Example:

from flask import Flask, request, jsonify
from secupy import KeyManager

app = Flask(__name__)

@app.route('/generate-key', methods=['POST'])
def generate_key():
    password = request.json.get('password')
    key_manager = KeyManager()
    key, salt = key_manager.generate_key(password)
    return jsonify({"Generated Key": key, "Salt": salt})

if __name__ == '__main__':
    app.run(debug=True)

Django Example:

from django.http import JsonResponse
from secupy import KeyManager

def generate_key(request):
    password = request.POST.get('password')
    key_manager = KeyManager()
    key, salt = key_manager.generate_key(password)
    return JsonResponse({"Generated Key": key, "Salt": salt})

Key Features:

  • Encryption: Secure message encryption and decryption with Fernet and RSA.
  • Password Hashing: Secure password hashing using bcrypt.
  • Message Authentication: HMAC-based signature generation and verification.
  • Key Management: Generate cryptographic keys securely using PBKDF2.
  • Asymmetric Encryption: RSA-based public and private key encryption.

License

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


Conclusion

The Secupy library provides a powerful set of tools for handling encryption, decryption, hashing, and secure communication tasks in your applications. Whether you're building a web application in Flask or Django, integrating these features will help secure sensitive data and ensure the integrity of your communications.


This README provides all necessary details for developers to understand and implement the Secupy library within Flask and Django projects. It should be clear and professional for any developer using this in production environments.

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

secupy-0.1.0.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

secupy-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file secupy-0.1.0.tar.gz.

File metadata

  • Download URL: secupy-0.1.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for secupy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8fb3911c5ef83beeab4df08988a04b9407be9d353ad8bc07fa14111c82cdca71
MD5 311114ad64426fa40f48d49fe14a31f4
BLAKE2b-256 5eac3e05ec2b0af2544b08e127f3334dd95798914a8a89fc5d27ab4327370c69

See more details on using hashes here.

File details

Details for the file secupy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: secupy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for secupy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5cf2671eecde75a3d45fb7a4a7504a6c22302c05515966c26bd1dbea11d7e93
MD5 cfc07bcf4429418f8a4c53307cdc1eb3
BLAKE2b-256 f726cee4a931190809bfa01219fa0522a1c7888498f9edc8e92c1527624b2bf7

See more details on using hashes here.

Supported by

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