Skip to content

Releases: modothprav/file-encryption-java

Part 4 - Different Algorithms and Key lengths

16 Aug 07:27
e135172
Compare
Choose a tag to compare

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
  • Can specify between Blowfish and AES 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

11 Aug 13:35
891efdd
Compare
Choose a tag to compare

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

Part 2 - Chosen Plaintext Attack Security

05 Aug 14:20
c207690
Compare
Choose a tag to compare

Specifications

  • Encrypts a plaintext file into a ciphertext file
  • Prints out the vector and computed mac 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 and vector
  • 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

28 Jul 13:16
e8d446a
Compare
Choose a tag to compare

Specifications

  • Encrypts a plaintext file into a ciphertext file
  • Prints out the Secret key and vector after generation during encryption
  • Need to specify the secret key and vector during decryption
  • Uses char arrays instead of strings for sensitive information such as the key and vector
  • 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]