Releases: modothprav/file-encryption-java
Releases · modothprav/file-encryption-java
Part 4 - Different Algorithms and Key lengths
Specifications
- Encrypts a plaintext file into a ciphertext file
- Prints out the
vector
, computedmac
andsalts
after generation during encryption - Need to specify the
password
during decryption and encryption - Secret key is generated by hashing passwords with a random salt
- Can specify between
Blowfish
andAES
algorithms - Can specify secret key length
- 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
- Allows user to query metadata of an encrypted 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 FileEncryptor enc Blowfish "password" plaintext.txt ciphertext.enc
% java FileEncryptor enc 192 "password" plaintext.txt ciphertext.enc
% java FileEncryptor enc AES 256 "password" plaintext.txt ciphertext.enc
Decryption
% java FileEncryptor dec "password" ciphertext.enc plaintext.txt
Query Metadata
% java FileEncryptor info ciphertext.enc
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
Part 3 - Password Based Encryption and Decryption
Specifications
- Encrypts a plaintext file into a ciphertext file
- Prints out the
vector
, computedmac
andsalts
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
Part 2 - Chosen Plaintext Attack Security
Specifications
- Encrypts a plaintext file into a ciphertext file
- Prints out the
vector
and computedmac
after generation during encryption - Need to specify only the
key
during decryption - Computed a Message Authentication code,
mac
to check for authentication and integrity - Extra option
key
will generate and print a random Base64 to the command line - 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
key
andvector
- Clears the char arrays after use
Chosen Plaintext Attack Security - Demo
General Commands
Encryption
% java FileEncryptor enc ((base 64 encoded key)) plaintext.txt ciphertext.enc
% java -jar Part2.jar enc ((base 64 encoded key)) plaintext.txt ciphertext.enc
Decryption
% java FileEncryptor dec ((base 64 encoded key)) ciphertext.enc plaintext.txt
% java -jar Part2.jar dec ((base 64 encoded key)) ciphertext.enc plaintext.txt
Key Generation - for testing
% java FileEncryptor key
% java -jar Part2.jar key
Output
<---------------------------------------->
Secret Key is: rH6FQud7wd6hh/+M3mr3tg==
Computed Mac: mbHWOsw72VL0CbSHyI1iEDECa1NZYLt1/u9iWTXAjWc=
<---------------------------------------->
INFO: Encryption finished, saved at ciphertext.enc
INFO: Authentication passed, file integrity maintained
INFO: Decryption complete, open decrypted.txt
Secret Key is: S9RZUKrFLmtTDc2GVqFwUg==
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 [Key] [inputFile] [outputFile]
Valid Decryption command: java FileEncryptor dec [Key] [inputFile] [outputFile]
Valid Key generation command: java FileEncryptor key
NOTE: The key specified must be Base64 Encoded
Exception in thread "main" java.lang.IllegalArgumentException: Neither enc (encrypt) or dec (decrypt) option specified
Valid Encryption command: java FileEncryptor enc [Key] [inputFile] [outputFile]
Valid Decryption command: java FileEncryptor dec [Key] [inputFile] [outputFile]
Valid Key generation command: java FileEncryptor key
NOTE: The key specified must be Base64 Encoded
Exception in thread "main" java.lang.IllegalArgumentException: Key provided must be Base64 encoded
Valid Encryption command: java FileEncryptor enc [Key] [inputFile] [outputFile]
Valid Decryption command: java FileEncryptor dec [Key] [inputFile] [outputFile]
Valid Key generation command: java FileEncryptor key
NOTE: The key specified must be Base64 Encoded
Exception in thread "main" java.lang.SecurityException: Authentication failed, file may have been tampered with
Part 1 - Performing Symmetric encryption and decryption
Specifications
- Encrypts a plaintext file into a ciphertext file
- Prints out the Secret
key
andvector
after generation during encryption - Need to specify the secret
key
andvector
during decryption - Uses char arrays instead of strings for sensitive information such as the
key
andvector
- Clears the char arrays after use
General Commands
Encryption
% java FileEncryptor enc plaintext.txt ciphertext.enc
% java -jar Part1.jar enc plaintext.txt ciphertext.enc
Decryption
% java FileEncryptor dec ((base 64 encoded key)) ((base 64 IV)) ciphertext.enc plaintext.txt
% java -jar Part1.jar dec ((base 64 encoded key)) ((base 64 IV)) ciphertext.enc plaintext.txt
Output
<---------------------------------------->
Secret Key is: rH6FQud7wd6hh/+M3mr3tg==
IV is: dqjpvRRLT0RDctfsJbMxFA==
<---------------------------------------->
INFO: Encryption finished, saved at ciphertext.enc
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 [inputFile] [outputFile]
Valid Decryption command: java FileEncryptor dec [Key] [Vector] [inputFile] [outputFile]
Exception in thread "main" java.lang.IllegalArgumentException: Neither enc (encrypt) or dec (decrypt) option specified
Valid Encryption command: java FileEncryptor enc [inputFile] [outputFile]
Valid Decryption command: java FileEncryptor dec [Key] [Vector] [inputFile] [outputFile]