Secure Data Transmission using
Hybrid cryptography
AIM
This project aims to implement a secure method of data transmission using Hybrid
Cryptography, combining the speed of AES (Advanced Encryption Standard) and the security of
RSA (Rivest–Shamir–Adleman). The project allows users to encrypt and decrypt text messages,
files, and images, ensuring that only authorized parties can access the data. It simulates a real-
time secure communication model for academic demonstration.
INTRODUCTION
With the rise of digital communication, data security is a major concern. Cryptography ensures
confidentiality, integrity, and authenticity. Hybrid Cryptography uses the best features of
symmetric and asymmetric encryption. In this project, we use AES for encrypting data and RSA
for encrypting the AES key, resulting in a secure and fast solution.
OBJECTIVE
To build a simple, secure cryptographic model in Python for encrypting and decrypting:
Text messages
Files (e.g., PDFs, documents)
Images (e.g., JPG, PNG).
EXISTING SYSTEM VS PROPOSED SYSTEM
EXISTING SYSTEM PROPOSED SYSTEM
Uses only AES or RSA Combines AES and RSA
AES alone is fast but key distribution is weak RSA is used to securily transmit AES key.
Not flexible with multiple file types. Supports text,files,and images.
METHODOLOGY
1. User selects the type of data (Text/File/Image)
2. System generates AES key and RSA key pair
3. Data is encrypted using AES
4. AES key is encrypted using RSA public key
5. Encrypted data and key are saved
6. During decryption:
AES key is decrypted using RSA private key.
Then original data is recovered using the AES key.
TECHNOLOGIES USED
Language: Python
Libraries:
pycryptodome – for RSA and AES encryption
os, base64 – for file handling and encoding
IDE: Visual Studio Code / Command Prompt
File Types Supported: .txt, .jpg, .png, .pdf, etc.
IMPLEMENTATION
from [Link] import AES, PKCS1_OAEP
from [Link] import RSA
from [Link] import get_random_bytes
import os
# Output logging
output_lines = []
def log(msg):
print(msg)
output_lines.append(str(msg))
def save_output():
with open("[Link]", "w", encoding="utf-8") as f:
[Link]("\n".join(output_lines))
def generate_rsa_keys():
key = [Link](2048)
private_key = key.export_key()
public_key = [Link]().export_key()
return private_key, public_key
def encrypt_aes(data, aes_key):
cipher = [Link](aes_key, AES.MODE_EAX)
ciphertext, tag = cipher.encrypt_and_digest(data)
return [Link], tag, ciphertext
def decrypt_aes(nonce, tag, ciphertext, aes_key):
cipher = [Link](aes_key, AES.MODE_EAX, nonce=nonce)
return cipher.decrypt_and_verify(ciphertext, tag)
def encrypt_rsa(data, public_key):
rsa_key = RSA.import_key(public_key)
cipher = PKCS1_OAEP.new(rsa_key)
return [Link](data)
def decrypt_rsa(encrypted_data, private_key):
rsa_key = RSA.import_key(private_key)
cipher = PKCS1_OAEP.new(rsa_key)
return [Link](encrypted_data)
def process_text():
message = input("Enter the text to encrypt: ").encode()
private_key, public_key = generate_rsa_keys()
log(f"RSA Public Key:\n{public_key.decode()}")
log(f"RSA Private Key:\n{private_key.decode()}")
log(f"Original Message: {[Link]()}")
aes_key = get_random_bytes(16)
nonce, tag, ciphertext = encrypt_aes(message, aes_key)
encrypted_key = encrypt_rsa(aes_key, public_key)
log(f"Encrypted AES Key (RSA encrypted): {encrypted_key}")
log(f"Encrypted Message (AES encrypted): {ciphertext}")
decrypted_key = decrypt_rsa(encrypted_key, private_key)
decrypted_message = decrypt_aes(nonce, tag, ciphertext, decrypted_key)
log(f"Decrypted Message: {decrypted_message.decode()}")
def process_file():
file_path = input("Enter full path of file or image to encrypt: ").strip()
if not [Link](file_path):
log("Invalid file path.")
return
with open(file_path, "rb") as f:
data = [Link]()
private_key, public_key = generate_rsa_keys()
log(f"RSA Public Key:\n{public_key.decode()}")
log(f"RSA Private Key:\n{private_key.decode()}")
log(f"Original Data Size: {len(data)} bytes")
aes_key = get_random_bytes(16)
nonce, tag, ciphertext = encrypt_aes(data, aes_key)
encrypted_key = encrypt_rsa(aes_key, public_key)
with open("encrypted_data.bin", "wb") as ef:
[Link](ciphertext)
log(f"Encrypted AES Key (RSA encrypted): {encrypted_key[:64]}...")
log(f"Encrypted data saved to 'encrypted_data.bin'")
decrypted_key = decrypt_rsa(encrypted_key, private_key)
decrypted_data = decrypt_aes(nonce, tag, ciphertext, decrypted_key)
with open("decrypted_output", "wb") as df:
[Link](decrypted_data)
log(f"Decrypted data saved to 'decrypted_output'")
def main():
while True:
log("Choose input type:")
log("1. Text")
log("2. File (any type)")
choice = input("Enter choice (1 or 2) or 'exit' to quit: ")
if choice == "1":
process_text()
elif choice == "2":
process_file()
elif [Link]() == 'exit':
break
else:
log("Invalid choice. Please enter 1, 2, or 'exit'.")
save_output()
log("All outputs saved to '[Link]'")
continue_choice = input("Do you want to perform another operation? (yes/no): ")
if continue_choice.lower() != 'yes':
break
log("Program ended. Goodbye!")
if __name__ == "__main__":
main()
OUTPUT
TEXT ENCRYPTION
FILE ENCRYPTION
Encryption
Decryption
IMAGE ENCRYPTION
ADVANTAGES
Combines speed and security.
Easy to use for different file types.
Output saved securely.
Simulates real-world encryption.
APPLICATIONS
Secure email systems.
Safe cloud storage.
End-to-end encrypted communication.
Government and defense data protection.
CONCLUSION
This project successfully demonstrates how Hybrid Cryptography enhances data security by
combining RSA and AES. It ensures that data, whether text or files, can be transmitted securely.
The model can be further enhanced for real-time chat apps or enterprise-level systems.
******THANK YOU******