Specifications
- Encrypts a plaintext file into a ciphertext file
- Prints out the
vector
, computed mac
and salts
after generation during encryption
- Need to specify the
password
during decryption and encryption
- Secret key is generated by hashing passwords with a random salt
- Computed a Message Authentication code,
mac
to check for authentication and integrity
- Writes metadata during encryption in ciphertext file
- Reads metadata during decryption from ciphertext file
- Uses char arrays instead of strings for sensitive information such as the
password
- Clears the char arrays after use
General Commands
Encryption
% java FileEncryptor enc "password" plaintext.txt ciphertext.enc
% java -jar Part3.jar enc "password" plaintext.txt ciphertext.enc
Decryption
% java FileEncryptor dec "password" ciphertext.enc plaintext.txt
% java -jar Part3.jar dec "password" ciphertext.enc plaintext.txt
Output
<---------------------------------------->
Secret Key: 4v3GURNUyxpT+wQ7V+7lnA==
Init Vector: Myg7C+La5xo7A9czkMvSlA==
Salt: FbXNYM6ofed26t/GY27/tQ==
Mac Key: XgYmnjFXo0aKTxGMc00uVHoeNYvXBTwRV5teJM8TitU=
Mac salt: 3X0+fVGznlZQtXN+4QW7aA==
Computed Mac: yiB/ldtDwyKMt4vcPfja+TC9guC+xzgoexFj+ciC6k8=
<---------------------------------------->
INFO: Encryption finished, saved at ciphertext.enc
<---------------------------------------->
Secret Key: 4v3GURNUyxpT+wQ7V+7lnA==
Init Vector: Myg7C+La5xo7A9czkMvSlA==
Salt: FbXNYM6ofed26t/GY27/tQ==
Mac Key: XgYmnjFXo0aKTxGMc00uVHoeNYvXBTwRV5teJM8TitU=
Mac salt: 3X0+fVGznlZQtXN+4QW7aA==
Computed Mac: yiB/ldtDwyKMt4vcPfja+TC9guC+xzgoexFj+ciC6k8=
Given Mac: yiB/ldtDwyKMt4vcPfja+TC9guC+xzgoexFj+ciC6k8=
<---------------------------------------->
INFO: Authentication passed, file integrity maintained
INFO: Decryption complete, open decrypted.txt
Error Messages
SEVERE: Unable to decrypt
SEVERE: Ensure the correct Key, Vector, and Files paths are specified
Exception in thread "main" java.lang.IllegalArgumentException: Not Enough Argunments specified
Valid Encryption command: java FileEncryptor enc [Password] [inputFile] [outputFile]
Valid Decryption command: java FileEncryptor dec [Password] [inputFile] [outputFile]
Exception in thread "main" java.lang.IllegalArgumentException: Neither enc (encrypt) or dec (decrypt) option specified
Valid Encryption command: java FileEncryptor enc [Password] [inputFile] [outputFile]
Valid Decryption command: java FileEncryptor dec [Password] [inputFile] [outputFile]
Exception in thread "main" java.lang.IllegalArgumentException: Key provided must be Base64 encoded
Valid Encryption command: java FileEncryptor enc [Password] [inputFile] [outputFile]
Valid Decryption command: java FileEncryptor dec [Password] [inputFile] [outputFile]
Exception in thread "main" java.lang.SecurityException: Authentication failed, file may have been tampered with