This project implements a Public Key Infrastructure (PKI) using Flask, providing a simple web-based interface for two users (User A and User B) to perform secure file operations such as signing, encryption, and their combinations.
- Python >= 3.8
-
Clone the Repository:
cd cyber-project -
Install Dependencies:
python3 -m venv .venv -
Install Dependencies:
.venv/Scripts/activate -
Install Dependencies:
pip install -r requirements.txt -
Generate Keys: Run the
__init__.pyscript to generate the required key pairs for User A and User B. This script creates private and public key files for each user in thekeysdirectory.python __init__.py -
Run the Flask App:
flask --app app.py runThe Flask app will start running at
http://127.0.0.1:5000/(by default).
User A has the ability to sign files, encrypt files, and perform both signing and encryption on files.
-
Sign File:
- Access the User A interface at
http://127.0.0.1:5000/user_a. - Choose the "Sign" action and select a file to upload.
- The signed file will be saved in the
signeddirectory.
- Access the User A interface at
-
Encrypt File:
- Access the User A interface at
http://127.0.0.1:5000/user_a. - Choose the "Encrypt" action and select a file to upload.
- The encrypted file will be saved in the
encrypteddirectory.
- Access the User A interface at
-
Sign and Encrypt File:
- Access the User A interface at
http://127.0.0.1:5000/user_a. - Choose the "Sign and Encrypt" action and select a file to upload.
- The signed and encrypted file will be saved in the
signed_and_encrypteddirectory.
- Access the User A interface at
User B can validate signatures, decrypt files, and perform both signature validation and decryption.
-
Validate Signature:
- Access the User B interface at
http://127.0.0.1:5000/user_b. - Choose the "Validate Signature" action and select a signed file to upload.
- User B will be notified if the signature is valid and the file originated from User A.
- Access the User B interface at
-
Decrypt File:
- Access the User B interface at
http://127.0.0.1:5000/user_b. - Choose the "Decrypt" action and select an encrypted file to upload.
- The decrypted file content will be displayed.
- Access the User B interface at
-
Decrypt and Verify Signature:
- Access the User B interface at
http://127.0.0.1:5000/user_b. - Choose the "Decrypt and Verify Signature" action and select a signed and encrypted file to upload.
- User B will be notified if the signature is valid, and the decrypted file content will be displayed.
- Access the User B interface at
keys/: Contains generated private and public key pairs for User A and User B.uploads/: Temporary storage for user-uploaded files.signed/: Location for storing files signed by User A.encrypted/: Location for storing files encrypted by User A for User B.signed_and_encrypted/: Location for storing files signed and encrypted by User A for User B.
This Flask-based Public Key Infrastructure (PKI) project employs various cryptographic techniques to ensure the security and integrity of file operations. Below are the key cryptographic techniques used in the implementation:
- Purpose: Used for secure communication between User A and User B.
- Implementation:
- Key Generation: RSA key pairs (public and private) are generated using
cryptography.hazmat.primitives.asymmetric.rsa. - File Encryption: Public key encryption is employed for encrypting symmetric keys, ensuring only the intended recipient (User B) can decrypt the file.
- Key Generation: RSA key pairs (public and private) are generated using
- Purpose: Used for efficient bulk data encryption.
- Implementation:
- Key Generation: Symmetric keys are derived using the PBKDF2-HMAC key derivation function.
- File Encryption: AES encryption is applied to the actual file content, securing the confidentiality of the data.
- Purpose: Ensures the authenticity and integrity of files signed by User A.
- Implementation:
- Signing: Files are signed using RSA-PSS (Probabilistic Signature Scheme) with SHA-256 hash function.
- Verification: User B can verify the signature using User A's public key.
- Purpose: Adds security features to asymmetric encryption.
- Implementation:
- OAEP Padding: Optimal Asymmetric Encryption Padding (OAEP) is applied for secure encryption and decryption using RSA.
- Purpose: Distinguishes different components of the processed files.
- Implementation:
- Custom Delimiter: Files are separated into distinct sections (e.g., encrypted key, ciphertext, signature) using a custom delimiter (
custom_delimiter), facilitating proper parsing during operations.
- Custom Delimiter: Files are separated into distinct sections (e.g., encrypted key, ciphertext, signature) using a custom delimiter (
- Purpose: Used for hashing and integrity verification.
- Implementation:
- SHA-256: Applied in various cryptographic operations, including key derivation, digital signatures, and padding schemes.
These cryptographic techniques collectively provide a secure foundation for file operations, ensuring confidentiality, integrity, and authenticity in the PKI infrastructure implemented in this Flask project.
-
The
__init__.pyscript generates RSA key pairs for User A and User B. If keys already exist, it will not generate new ones. -
For security purposes, it is recommended to use a stronger secret key than the one specified in
app.py. Modify theSECRET_KEYinapp.pyaccordingly. -
This project is intended for educational purposes and may require further enhancements for production use, such as error handling, secure key management, and proper file handling.
Feel free to explore and extend the functionality as needed. Enjoy secure file operations with Flask and PKI!


