@@ -45,7 +45,7 @@ public static void main(String[] args) throws Exception {
4545 if (args .length < 1 ) { throw new IllegalArgumentException ("Not Enough Argunments specified\n " + validCmdMsg ); }
4646
4747 // Convert String arguments to char arrays
48- char [][] charArgs = Util .getCharArgunments (args );
48+ char [][] charArgs = Util .getCharArguments (args );
4949
5050 // Clear String argunments
5151 Arrays .fill (args , null );
@@ -56,9 +56,7 @@ public static void main(String[] args) throws Exception {
5656 return ;
5757 }
5858
59- if (charArgs .length < 4 ) {
60- throw new IllegalArgumentException ("Not Enough Argunments Provided\n " + validCmdMsg );
61- }
59+ if (charArgs .length < 4 ) { throw new IllegalArgumentException ("Not Enough Argunments Provided\n " + validCmdMsg ); }
6260
6361 // Options Available
6462 char [] enc = "enc" .toCharArray ();
@@ -68,7 +66,7 @@ public static void main(String[] args) throws Exception {
6866 throw new IllegalArgumentException ("Neither enc (encrypt) or dec (decrypt) option specified\n " + validCmdMsg );
6967 }
7068
71- byte [] key ;
69+ byte [] key = new byte [ 16 ] ;
7270 try {
7371 key = Base64 .getDecoder ().decode (Util .convertCharToByte (charArgs [1 ]));
7472 } catch (IllegalArgumentException e ) {
@@ -113,7 +111,7 @@ public static void encrypt(byte[] key, String inputPath, String outputPath) thro
113111 NoSuchPaddingException , InvalidKeyException , InvalidAlgorithmParameterException , IOException {
114112 //Generate Initilisation Vector
115113 SecureRandom sr = new SecureRandom ();
116- byte [] initVector = new byte [16 ];
114+ final byte [] initVector = new byte [16 ];
117115 sr .nextBytes (initVector ); // 16 bytes IV
118116
119117 // Initialize Vector and Keys
@@ -136,7 +134,7 @@ public static void encrypt(byte[] key, String inputPath, String outputPath) thro
136134
137135 // Compute Mac for authentication
138136 hmac .update (initVector );
139- byte [] mac = computeMac (hmac , plaintextFile );
137+ final byte [] mac = computeMac (hmac , plaintextFile );
140138
141139 // Display the Base64 encoded versions of Vector and computed mac
142140 System .out .print ("\n <---------------------------------------->\n " );
@@ -206,7 +204,8 @@ private static byte[] computeMac(Mac hmac, Path filePath) {
206204 hmac .update (bytes , 0 , length );
207205 }
208206 } catch (IOException e ) {
209-
207+ LOG .log (Level .SEVERE , "IOException caught - Please check filepath specified" );
208+ System .exit (0 );
210209 }
211210
212211 return hmac .doFinal ();
@@ -275,12 +274,13 @@ public static void decrypt(byte[] key, String inputPath, String outputPath) thro
275274 * @throws InvalidKeyException
276275 * @throws InvalidAlgorithmParameterException
277276 */
278- private static boolean writeDecryptedFile (Path inputPath , Path outputPath , byte [] key ) throws NoSuchAlgorithmException , NoSuchPaddingException , InvalidKeyException , InvalidAlgorithmParameterException {
277+ private static boolean writeDecryptedFile (Path inputPath , Path outputPath , byte [] key ) throws NoSuchAlgorithmException ,
278+ NoSuchPaddingException , InvalidKeyException , InvalidAlgorithmParameterException {
279279 try (InputStream encryptedData = Files .newInputStream (inputPath );){
280280
281281 // Read metadata from the input file
282- byte [] initVector = new byte [16 ];
283- byte [] givenMac = new byte [32 ];
282+ final byte [] initVector = new byte [16 ];
283+ final byte [] givenMac = new byte [32 ];
284284
285285 encryptedData .read (initVector );
286286 encryptedData .read (givenMac );
@@ -290,7 +290,7 @@ private static boolean writeDecryptedFile(Path inputPath, Path outputPath, byte[
290290 SecretKeySpec skeySpec = new SecretKeySpec (key , ALGORITHM );
291291 SecretKeySpec macKey = new SecretKeySpec (key , HASH_AlGORITHM );
292292
293- // Initialise cipher and HMac
293+ // Initialise cipher
294294 Cipher cipher = Cipher .getInstance (CIPHER );
295295 cipher .init (Cipher .DECRYPT_MODE , skeySpec , iv );
296296
0 commit comments