This project demonstrates the implementation of cryptographic principles, including file encryption and decryption using symmetric and asymmetric encryption techniques. It also explores secure key distribution and session management.
- Implementation of file encryption and decryption using DES in CBC mode.
- Two-process system for file encryption and decryption.
- Needham-Schroeder protocol for symmetric key distribution.
- Implementation of RSA for public key encryption and decryption.
- The use of Diffie-Hellman for secure session key agreement.
This script handles file encryption and decryption using the DES algorithm in CBC mode.
pad_text
: Adds padding to plaintext to meet DES block size requirements.remove_padding
: Removes padding from decrypted text.encrypt_file
:- Generates a symmetric key and IV.
- Encrypts a file using DES in CBC mode.
- Writes the encrypted content to an output file.
decrypt_file
:- Reads the IV and encrypted content.
- Decrypts the file using the symmetric key.
- Place the input file in the designated
input
directory. - Run the script. The key and IV are displayed in the console.
- The encrypted file will be saved in the
output
directory. - The decryption process reads the key and outputs the decrypted file in the
output
directory.
python DES.py
This script implements a Key Distribution Center (KDC) following the Needham-Schroeder protocol.
register_client
: Registers clients with the KDC.create_nonce
: Generates a unique nonce.create_session_key
: Generates a random session key.request_session
:- Validates client credentials.
- Generates a session key for communication.
- Creates messages for both clients and an encrypted ticket for the recipient.
- Client Class:
- Handles session requests and message verification.
- Register clients with the KDC using the
register_client
method. - Use the
request_session
method to establish communication between clients. - Verify messages using the
verify_message
method.
python KDC.py
This script implements:
- RSA encryption and decryption for file content.
- Diffie-Hellman key exchange for secure session key agreement.
generate_key_pair
: Generates RSA key pairs and saves them to files.load_key
: Loads an RSA key from a file.encrypt_file
:- Encrypts a file using RSA for the session key and AES for the file content.
decrypt_file
:- Decrypts the session key using RSA.
- Decrypts the file content using AES.
implement_diffie_hellman
:- Implements Diffie-Hellman key exchange to generate a shared secret between two parties.
- Generate RSA key pairs using
generate_key_pair
. - Use the public key of the recipient to encrypt the file.
- Decrypt the file using the private key of the recipient.
- Optionally, use the
implement_diffie_hellman
function for session key agreement.
python RSADH.py
- A symmetric key algorithm.
- Operates in CBC mode for added security.
- Requires padding to process plaintext.
- An asymmetric encryption algorithm.
- Used for secure key exchange and file encryption.
- Facilitates secure session key generation over an insecure channel.
- Ensures both parties derive the same shared secret.
- Provides secure symmetric key distribution using a trusted third party (KDC).
- Ensures freshness of communication with nonce values.
This project is distributed under the Apache 2.0 license. See
LICENSE.txt
for more information.