4 min read
C File Encryptor

C File Encryptor

in today’s digital age, everyone can admit that data security is more important than ever. file encryption ensures that sensitive information is protected from unauthorized access. in this post, i would explore how to build a simple file encryptor in c, implementing both encryption and decryption modes. the project uses the advanced encryption standard (aes) and includes password-based encryption, integrity checks, and error handling.

although, we would work around making sure it has file selection for encryption and decryption, aes encryption with a password/key, error handling for incorrect input or key, progress feedback during encryption/decryption, file integrity verification using sha-256, and cli-based interaction. i will try my best to do more

i used the openssl library for encryption and hashing

Features I remember

  • ability to select or specify a file to encrypt or decrypt.
  • option to choose between different encryption algorithms if needed.
  • implement a strong encryption algorithm (specifically aes and des)
  • users can provide a password or an encryption key to secure the file.
  • generate a secure random key if none is provided by the user.
  • display progress during encryption/decryption, especially for large files.
  • use a hash (sha-256) to verify the integrity of the file after decryption to ensure it hasn’t been tampered with.
  • graceful handling of errors like wrong key/password, file read/write failures, and unsupported formats.
  • ensure that the file encryptor works across different operating systems (windows, linux, macos).
  • added a simple command-line interface (cli) with flags to specify encryption options.
  • store metadata like encryption date, algorithm used, and any specific parameters used in a separate header file or inside the encrypted file itself.
  • adding more features soon
  • considering the option to compress the file before encryption to save space.

🚀 More Information

hear me out!

i am just testing a theory on mac, might even delete this. cause i have not actually used any of my macbooks to code C before this time. so i am trying out multiple things. it’s always been on my pc.

let me explain how you can use it sef

  1. just run make to build the file (i have done all the work for you)
  2. if you get issues, just use make clean and then make again to clean and rebuild
  3. okay, back to the stuff i am explaining, after building, run the program for encryption:
./c-file-encryptor encrypt tests/test_input.txt tests/encrypted_output.txt secretkey
  1. then, run for decryption if you like:
./c-file-encryptor decrypt tests/encrypted_output.txt tests/decrypted_output.txt secretkey
  1. oh, i forgot to make clear that i put the test file in tests/test_input.txt file, but then this is what i used in the text input:
oya now, this is my test file. make we see if the encryption and decryption dey work well.
  1. to those that are oversabinus like me, you can do some debugging sha. just add print statements to main.c file and then check the value of all arguments like the argc, the arg[1] and every other.
printf("argc: %d\n", argc);
for (int i = 0; i < argc; i++) {
    printf("argv[%d]: %s\n", i, argv[i]);
}

my motivation

it is shit!