Welcome to the Cryptography project! In this project, you will implement programs to perform public-key encryption, compute cryptographic checksums (keyless and keyed), and verify the integrity of files using these checksums.
-
Create a file called
sensitive.txt
in the current directory. -
Write a program called
generate_keys
that generates a pair of 3072-bit RSA keys and saves the public key to a file calledpub_key
and the private key to a file calledpriv_key
.
To run the program, open a terminal window and type generate_keys
. Then, display the contents of pub_key and priv_key using the hexdump command.
- Write a program called
encrypt_file
that encrypts the contents ofsensitive.txt
using the public key in pub_key. The encrypted file will overwrite the originalsensitive.txt
. Make sure that the original (unencrypted)sensitive.txt
is in the same directory as the program.
To run the program, open a terminal window and type
encrypt_file
. Then, display the first 100 bytes of the encryptedsensitive.txt
using the hexdump command.
- Write a program called
decrypt_file
that decrypts the contents ofsensitive.txt
using the private key inpriv_key
. The decrypted file will overwrite the encryptedsensitive.txt
. Make sure that the encryptedsensitive.txt
is in the same directory as the program.
To run the program, open a terminal window and type
decrypt_file
. Then, display the first 100 bytes of the decryptedsensitive.txt
using the head command.
- Write a program called
compute_checksum
that computes a keyless cryptographic checksum of sensitive.txt using the SHA256 hash function. The checksum should be written to a file calledsensitive_checksum.txt
in text format.
Display the checksum of
sensitive_checksum.txt
using thecat
command.
-
Write a program called
verify_checksum
that computes a checksum of sensitive.txt using SHA256 and compares it with the contents ofsensitive_checksum.txt
. If the resulting hash values are the same, the program should output "Accept!" and otherwise it should output "Reject!". -
Write a program called
compute_keyed_checksum
that works similarly tocompute_checksum
, but instead ofSHA256
, it should use the keyed hash functionHMAC-SHA256
. A 256-bit key should be read from a file calledkey.bin
. The checksum should be written to a file calledsensitive_keyed_checksum.txt
in text format.
The file
key.bin
can be created using the commandhead -c 256 /dev/urandom > key.bin
Display the checksum of
sensitive_keyed_checksum.txt
using thecat
command.
- Write a program called
verify_keyed_checksum
that works similarly toverify_checksum
, but it should compute a keyed checksum ofsensitive.txt
using HMAC-SHA256 and compare it with the contents ofsensitive_keyed_checksum.txt
. If the resulting values are the same, the program should output "Accept!" and otherwise it should output "Reject!".