Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 4 Encryption [ 4 0 marks ] Develop a program named MAC, which simulates a Message Authentication Code. This program should accept four parameters:

Question 4 Encryption [40 marks]
Develop a program named MAC, which simulates a Message Authentication Code. This
program should accept four parameters: the option ("gen" or "verify"), the name of the AES
file, the input file, and the MAC file (for generation or verification).
The program will read an AES key that has been generated by the provided program,
RandomAESKeyGen. If the chosen option is "gen", it will calculate the SHA-1 hash of the
input file, encrypt this hash using the AES key, and write the encrypted data to the specified
MAC file. If the chosen option is "verify", it will again calculate the SHA-1 hash of the input
file and encrypt it using the AES key. The result will then be compared with the content of the
specified MAC file. If the two match, 'Verification: Successful!' will be displayed; if not,
'Verification: Failed!' will be displayed. For both options, the digest is displayed in base64
format.
The RandomAESKeyGen program is provided for you, which generates a random AES key
and writes to the file specified in the input parameter.
Below are sample outputs from compiling and running the program.
> javac a2\RandomAESKeyGen.java
> javac a2\MAC.java
> java a2.RandomAESKeyGen my_aes.key
> java a2.MAC gen my_aes.key notes.txt notes.txt.mac
The digest is (in base64 format): JkSYEkH5rRBIlayDdI1SuGI4Qto=
> java a2.MAC verify my_aes.key notes.txt notes.txt.mac
The digest is (in base64 format): JkSYEkH5rRBIlayDdI1SuGI4Qto=
Verification: Successful!
If the notes.txt is modified
> java a2.MAC verify my_aes.key notes.txt notes.txt.mac
The digest is (in base64 format): Lk/Oa44NojNXCBPcTwSRyzttIGM=
Verification: Failed!
If the mode is incorrect
> java a2.MAC verify my_aes.key notes.txt notes.txt.mac
Incorrect modeDevelop a program named MAC, which simulates a Message Authentication Code. This
program should accept four narameters: the option ("gen" or "verify"), the name of the ?bar((?bar(A))ES)
file, the input file, and the ?bar(?bar(M))AC file (for generation or verification).
The program will read an AES key that has been generated by the provided program,
RandomAESKeyGen. If the chosen option is "gen", it will calculate the SHA-1 hash of the
input file, encrypt this hash using the AES key, and write the encrypted data to the specified
MAC file. If the chosen option is "verify", it will again calculate the SHA-1 hash of the input
file and encrypt it using the AES key. The result will then be compared with the content of the
specified MAC file. If the two match, 'Verification: Successful!' will be displayed; if not,
'Verification: Failed!' will be displayed. For both options, the digest is displayed in base 64
format.
The RandomAESKeyGen program is provided for you, which generates a random AES key
and writes to the file specified in the input parameter.
Below are sample outputs from compiling and running the program.javac a2\MAC.javajava a2.MAC gen my_aes.key notes.txt notes.txt.mac
The digest is (in base64 format): JkSYEkH5rRBIlayDdI1SuGI4Qto=The digest is (in base64 format): JkSYEkH5rRBIlayDdI1SuGI4Qto=
Verification: Successful!
If the notes.txt is modifiedThe digest is (in base64 format): Lk/Oa44NojNXCBPCTwSRyzttIGM=
Verification: Failed!
If the mode is incorrect
> java a2.MAC verify my_aes.key notes.txt notes.txt.mac
Incorrect mode
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions