Skip to main content

A simple AES and RSA encryption package

Project description

Encryption

GitHub

Overview

This script demonstrates cryptographic operations like AES encryption/decryption, RSA encryption/decryption, and hashing using Python's pycryptodome, base64, and hashlib library.

Features

AES Encryption (ECB): Encrypts and decrypts data using AES in ECB mode.
RSA Key Pair Generation: Creates 2048-bit RSA keys.
RSA Encryption/Decryption: Uses PKCS1_OAEP padding for secure RSA operations.
Hashing: Supports MD5, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512.

Dependencies

pip install -r requirements.txt

Function Details

AES Encryption/Decryption

aes_encrypt_ecb(data, key)

    Encrypts plaintext using AES in ECB mode.

    Args:

        data (str): The plaintext to encrypt.

        key (bytes): A key of length 16, 24, or 32 bytes.

    Returns:

        Encrypted data (bytes).Function Details
    
aes_decrypt_ecb(ciphertext, key)

    Decrypts AES-encrypted ciphertext in ECB mode.

    Args:

        ciphertext (bytes): The encrypted data.

        key (bytes):
            The decryption key.

    Returns:

        Decrypted plaintext (str).

RSA Encryption/Decryption

generate_rsa_keys()

    Generates a pair of RSA public and private keys.

    Returns:

        private_key (bytes): RSA private key.

        public_key (bytes): RSA public key.

rsa_encrypt(plaintext, public_key)

    Encrypts plaintext using an RSA public key.

    Args:

        plaintext (str): The plaintext to encrypt.

        public_key (bytes): The RSA public key.

    Returns:

        Encrypted data (bytes).

rsa_decrypt(encrypted_data, private_key)

    Decrypts RSA-encrypted data using a private key.

    Args:

        encrypted_data (bytes): The encrypted data.

        private_key (bytes): The RSA private key.

    Returns:

        Decrypted plaintext (str).

All hashing functions:

md5_hash(data): Generates an MD5 hash of the input data.

sha1_hash(data): Generates a SHA-1 hash.

sha224_hash(data): Generates a SHA-224 hash.

sha256_hash(data): Generates a SHA-256 hash.

sha384_hash(data): Generates a SHA-384 hash.

sha512_hash(data): Generates a SHA-512 hash.

Args: data (str): Input string to hash.

Returns: Hash value (str).

Outputs

RSA: Encrypts and decrypts plaintext securely.
AES: Encrypts and decrypts text using AES with a random key.
Hashing: Generates cryptographic hashes for text.

Security Notes

ECB mode leaks patterns; use safer modes like CBC or GCM for production.
This script is for educational purposes only.

License

This project is licensed under the Apache2 reset License

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

encryptions-1.0.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

encryptions-1.0.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file encryptions-1.0.0.tar.gz.

File metadata

  • Download URL: encryptions-1.0.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for encryptions-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a84c03c4394a6fbaca58e313807ed6a9f9062ce39b9223daaedfd1fadc7d34e5
MD5 90bcce60d20ba226f3942a08175aa273
BLAKE2b-256 426ade004588be13de817710a9e20339ce74aa95f860ab8c25bcba29b570fc5f

See more details on using hashes here.

File details

Details for the file encryptions-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: encryptions-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for encryptions-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d46bbfdac89b7b439aa79f61f4cf5df1e0ccc92b5bf25fa19828210420742cee
MD5 e5fef21e042b95ae20af981e15478387
BLAKE2b-256 5395d21205ebcabd04297546ba1c6af82c0b37ba86c86225f4b38219f3b92b22

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