I have tried doing this by encrypting individual files but I have a lot of data (~20GB) and hence it would take a lot of time. In my test it took 2.28 minutes to encrypt a single file of size 80MB. Is there a quicker way to be able to password protect that would apply to any any file (text/binary/multimedia)?
Asked
Active
Viewed 338 times
1
-
https://stackoverflow.com/questions/992019/java-256-bit-aes-password-based-encryption https://stackoverflow.com/questions/2442264/how-to-encrypt-decrypt-a-file-in-java https://stackoverflow.com/questions/27962116/simplest-way-to-encrypt-a-text-file-in-java – Hearen Aug 20 '18 at 05:59
-
Read them yet? Or this: https://stackoverflow.com/questions/13673556/using-password-based-encryption-on-a-file-in-java – Hearen Aug 20 '18 at 06:00
-
@Hearen Thanks for the comments. Sorry it took me some time to get back. I saw the posts above and I am able to do the same already but my concern is the time. Encrypting a file, especially multimedia could be very very slow. Which means I need to encrypt/decrypt every time and for 20GB+ this will take a lot of time. I was wondering if there is a quicker way than encrypting the whole file. – worldbeater Aug 24 '18 at 05:39
1 Answers
1
If you are just trying to hide the file from others, you can try to encrypt the file path instead of encrypting the whole huge file.
For the path you mentioned: text/binary/multimedia
, you can try to encrypt it by a method as:
private static String getEncryptedPath(String filePath) {
String[] tokens = filePath.split("/");
List<String> tList = new ArrayList<>();
for (int i = 0; i < tokens.length; i++) {
tList.add(Hashing.md5().newHasher() // com.google.common.hash.Hashing;
.putString(tokens[i] + filePath, StandardCharsets.UTF_8).hash().toString()
.substring(2 * i, 2 * i + 5)); // to make it impossible to encrypt, add your custom secret here;
}
return String.join("/", tList);
}
and then it becomes an encrypted path as:
72b12/9cbb3/4a5f3
Once you know the real path text/binary/multimedia
, any time you want to access the file, you can just use this method to get the real file path 72b12/9cbb3/4a5f3
.

Hearen
- 7,420
- 4
- 53
- 63
-
1Hey @Hearen Thanks for the solution. That approach is actually the closest to my requirements. Thanks a ton for the help. I will give it a try asap. – worldbeater Aug 24 '18 at 17:31