2

I would like to make video/audio/pdf files hidden inside Internal/External storage in Android. Our requirement is making the files visible only in our Android application but not any other apps like Es File Explorer and not even when connecting the device to Desktop/Laptop.

I have googled it a lot and found the following ways but with few disadvantages.

Creating folder/file with prefix "." - It has the disadvantages that we cannot prevent it to be visible in some File explorer apps with the option "Show hidden files" and we cannot prevent the files from getting displayed when connected to Desktop/Laptop.

Storing the files inside App specific folder - Storing large memory files in the path returned by android.Content.Context.getFilesDir() will lead to the poor performance of the device and most of the devices will not have large internal memory size.

How to overcome the disadvantages and make our application to meet the requirement ?

Rakesh L
  • 1,136
  • 4
  • 18
  • 44

2 Answers2

2

Your first proposed solution won't work since it would make files accessible to anyone. Second solution is perfect if you have limited file sizes. In case of large memory files it is always better to store them in External storage. But this would make it publicly accessible. To prevent that you can encrypt the files and store them in external storage.

Some suggestions while doing so :

  1. Randomise the filenames so won't be easy to guess.
  2. Refer this for simple file encryption.
  3. Do not use static key for encryption as it can be reverse engineered. Use different key for every file.
  4. Do not store the original key in db/shared preference. Store the hash of it instead.
  5. You can even hash the key n times and then store in db. This would make procedure a bit slow but provides more security as one has to know the exact value of n to get the original key.
  6. For added security you can even consider using Android's KeyStore to derive the IV.
Nilesh Deokar
  • 2,975
  • 30
  • 53
2

Well hiding files to user accessable storage is not recommend without encryption.

Youtube,Gaana, saavan, hotstar all these media related apps used to encrypt their data and stores in data location which is visible to users but they can't share or use in other ways as the data is encrypted.

You can use CipherOutputStream and CipherInputStream for encryption and decryption of file in android.

There are two ways through which you can achieve your goal

Download a file and encrypt it, when you want to play that file decry-pt it in a temporary file and play it which I not recommend as it can increase the chances of data grabbing.

if you want to play encrypted file on the fly (not decrypting it in a temp file) then you can use Libmedia library. It streams encrypted file on local host and play it from there

Original answer : https://stackoverflow.com/a/35426842/9565955

Woods
  • 91
  • 17
  • 1
    +1 Especialy for mentioning the real time apps such as Youtube,Gaana, saavan, hotstar and made to understand Libmedia library. – Rakesh L Apr 15 '18 at 05:20