This project is a sample C++ library that demonstrates how to encrypt and decrypt files or folders using a combination of 7zip archiving and multiple transformation algorithms. The encryption process includes:
-
Creating a Password-Protected Archive:
The input file or folder is compressed into a zip archive using the 7zip command-line tool with a provided password. -
Applying Transformation Algorithms:
A list of transformation algorithms (for example, AES and XOR) is applied in sequence to the zipped data.- During encryption, the algorithms are applied in the order specified (e.g., AES then XOR).
- During decryption, the algorithms are applied in reverse order (e.g., XOR then AES) to recover the original zipped archive.
-
Key Management:
A keys file is used to retrieve the encryption/decryption key. The first key is read and then removed from the file after each operation.
- 7zip Integration: Uses the 7zip command-line tool to create and extract password-protected archives.
- Pluggable Transformation Algorithms: Supports multiple transformation functions. Two default algorithms are provided:
- AES (using OpenSSL's EVP API)
- XOR (a simple, self-inverse algorithm)
- Flexible Architecture: Easily extend or replace transformation algorithms by implementing functions matching the provided signature.
- C++17 Compliant Compiler: e.g.
g++
- 7zip: Ensure the
7z
command-line tool is installed and available in your system's PATH. - OpenSSL: Required for AES encryption/decryption.
On Ubuntu, you can install it using:sudo apt-get install libssl-dev
Files in the Project
Encryptor.h: Header file defining the encryption/decryption interface and transformation algorithm structure.
Encryptor.cpp: Implementation of the encryption/decryption functions and default transformation algorithms.
main.cpp: Example usage demonstrating how to encrypt and decrypt a file.
README.md: This file.
Building the Project
Install Dependencies:
OpenSSL:
On Ubuntu:
sudo apt-get install libssl-dev
7zip:
Ensure that 7z is installed and accessible in your system’s PATH.
Prepare the Keys File:
Create a file named keys.txt in the project directory containing at least one key, for example:
mysecretkey anotherkey
Prepare the Input File/Folder:
Create a file or folder (for example, example.txt) with some sample content you want to encrypt.
Compile the Code:
Use a C++17 compliant compiler. For example, with g++:
g++ -std=c++17 -o encrypt_demo main.cpp Encryptor.cpp -lcrypto
Running the Executable
After building the project, run the executable:
./encrypt_demo
The program will:
Encrypt the specified input (e.g., example.txt) into an encrypted file (encrypted.dat) using the provided keys and transformation algorithms.
Then, it will decrypt the file back into a folder (decrypted_output).
Customization
Transformation Algorithms:
To add your own transformation algorithms, implement functions matching the TransformFunction signature and bundle them using the TransformAlgorithm structure. Then, add them to the transformation list.
7zip Commands:
Adjust the 7zip command strings in Encryptor.cpp as needed for your environment.
AES Settings:
The default AES functions use AES-256-CBC with a fixed zero IV for demonstration purposes. For production, ensure proper IV management and robust error handling.