- Timestamp:
- 01/20/20 15:04:45 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/encryption/io/EncryptedExpReader.java
r1461 r1500 2 2 3 3 import java.io.BufferedReader; 4 import java.io.File; 4 5 import java.io.FileInputStream; 5 6 import java.io.FileReader; … … 77 78 return true; 78 79 } 80 } 81 82 public static boolean isAccessibleExpediteeFile(String path, SecretKey key) throws IOException { 83 try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"))) { 84 String firstLine = in.readLine(); 85 if (firstLine == null) return false; 86 87 if (firstLine.startsWith(ENCRYPTED_EXP_FLAG)) { 88 String secondLine = in.readLine(); 89 byte[] toDecrypt = Base64.getDecoder().decode(secondLine); 90 byte[] decrypted = DecryptSymmetric(toDecrypt, key); 91 return decrypted != null; 92 } else { 93 // Not encrypted. Returns false because the caller of this 94 // function is asking if this key is used to decrypt this file. 95 return false; 96 } 97 } 79 98 } 80 99 … … 326 345 } catch (final NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException 327 346 | IllegalBlockSizeException | BadPaddingException e) { 328 e.printStackTrace(); 347 //e.printStackTrace(); 348 System.err.println("Failed to decrypt '" + new String(toDecrypt) + "' with key " + new String(key.getEncoded())); 329 349 return null; 330 350 } … … 337 357 super(in); 338 358 } 339 359 340 360 @Override 341 361 /**
Note:
See TracChangeset
for help on using the changeset viewer.