Password protect folder in android - android

I want to store media files in an external storage creating a folder . The folder is secured using a password and accessible by my app only. The user is allowed to create its own password. Any suggestions how to do this??

I don't think your approach is possible. Maybe you should think about encrypting the file contents, so that only your app will be able do access the actual content after decryption.

Encrypting files is not a solution! This only creates potential file loss and problems later. Also, it is slow and you rely on the app that encrypted the files to unencrypt them later. What if that app dies or is not longer available? You have lost your files.

External storage such as the SD card has no permissions associated with it. The closest you could do is to store your data in some encrypted form and as per requirement you can decrypt it also.
This is the link for how you can encrypt and decrypt your file.

Related

Android - How to hide files inside the Internal/External storage?

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 ?
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
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 :
Randomise the filenames so won't be easy to guess.
Refer this for simple file encryption.
Do not use static key for encryption as it can be reverse
engineered. Use different key for every file.
Do not store the original key in db/shared preference. Store the
hash of it instead.
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.
For added security you can even consider using Android's KeyStore to
derive the IV.

What is the best way to store a file within an Android app?

I am writing an app for my final year project, so it's more so for proof of concept so it doesn't have to be the best app in the world.
It is like a file locker app that you can add and remove files from the app and when they are stored they will be encrypted. There will be a login of some sort for the user to enter and be verified on a DB.
I am still a novice in android so I still have a way to go, but I am getting there!
I was thinking when the file (which could be a doc, pdf, jpg, video file etc) is added to the app it would be stored in the internal storage (from what I have read it seems to be the best place to store app related content) and a record of the name and file type would be added to the DB and also the encrypted file name. So when the user looks at the app they will see a thumbnail of the pic and the file name, kinda like the My Files app shows up files within a folder.
My question is it best not to store the file directly into the DB but just use the DB as a reference with the file details, if so how could this be done?
Also I was thinking that an AES 128bit encryption method would be best suited for this. I have tried a couple of encryption examples but have only been able to do this with a txt file, when i tried it with a jpg the app just sat there and did nothing. It showed the encrypted and decrypted jpg but this was not viewable.
Would anyone be able to suggest a good way of encrypting any file type that would suit for my app?
Any help would be greatly appreciated!
Cheers,
Owen
If you want to do this properly, here are a few tips:
Don't store files in the database, unless you know in advance that they're going to be really titchy. Store them somewhere else, with a reference to them in the database.
The best place for them if they're smallish is internal storage in the app's private file space. But if you want to be able to store encrypted arbitrary data then you'll need to hit external storage.
Don't store the decryption key!
Ideally, you should find a way not to write the file anywhere when you decrypt it. That might not be possible, though, if you need to open it in another application afterwards. If you write the encrypted files to external storage, you should at the very least write the decrypted version to internal storage where there's some operating system protection against other apps reading it. If you write the decrypted file to external storage, anything will be able to get at it.
AES with a 128-bit key will do you fine.

How to encrypt and decrypt folder in android sdcard

is it possible to encrypt the sd card folder r not please help me
if it possible , what is the processor of encryption and decryption
not possible , let me know what can i do for folder security in android sdcard
My file is here :/mnt/sdcard/image1.jpeg.
So How to encrypt this file in android please help me
and Android encryption support MBs r not
is it possible to encrypt the sd card folder r not please help me
Only by modifying the operating system and creating your own custom ROM.
not possible , let me know what can i do for folder security in android sdcard
If your objective is to allow the user to defend against other people stealing the user's data, you can encrypt individual files as part of how you store them. For example, you could use SQLCipher for Android to encrypt a SQLite database that you put on external storage.
If your objective is to hide data from the user, that is implausible. Your encryption algorithm and key will be in your app, which anyone can examine and use to get at the encrypted data. If you do not want users having access to certain pieces of data, do not put that data on the user's device.
Yes, you can encrypt and decrypt the files and folders in your sd card using java libraries. You can implement through javax.security package.
Below is the sample of Encryption and Decryption in java
Example 1
Example2
Example 3
Example 4
Take a Look at this Example

Android: Save a file to external memory

I have some audio files that my app is downloading, and due to the size of the files it would be nice if I could store them on the user's external storage. However I need them to remain private to my application. Is there any way to accomplish this?
Not literally.
You could encrypt them, but then you would have to handle the playing yourself, in order to decrypt them (or play some game like streaming them from a local "server" which decrypts them as it reads).
Realize also that even things within your .apk itself are accessible on most devices (you will need to use care in obfuscating the encryption key), and the contents of your app's private storage folder are readable on the multitude of rooted devices.
One simple suggestion would be to encrypt your file and then store it in external memory. This would keep the data safe and secured. Other application wont be able to access it. To accomplish this you need to convert the file into ByteStream. Then using encryption function encrypt it and store to external memory. Change the extension of your file to some user-defined extension like myExt and store all in certain folder. When you want to use those files in your application, decrypt it and use it. The encryption key will help you to securely protect data.
As per my knowledge this will prevent other application to access your information.

Files internal to applications

I read this sentence, form a book
"Files: Files internal to applications, which you can store on a
removable storage medium"
and I am confused, well I expect that "Files internal to applications" saved from my app that will be accessible only from my app. and that is true when you save them internally in the phone memory.
But as the sentence says , you can save files to the sdcard also. And that is great but I think that everyone with 'external storage read' privilege set in the manifest will be able to read your file, so that doesn't make it internal to the app, it makes it publicly available to everyone.
My question is:
Is there any way to store the files in the 'removable storage medium' -> sdcard and those files to stay available only to my app, others application to be prevented from reading the content ?
I know that if you put files in data/data//files these files are only available to the app with that package name
It is possible . For that you need to encrypt the data with some private key and write to SDCARD, when ever you want to process that data you have to decrypt it . So another app can't access your data without decrypt it.
Android Encryption Example.
store the files in the 'removable storage medium' -> sdcard and those files to stay available only to my app
I don't think so, For sdcard it is not possible.
The one way is store encrypted file in sdcard and key for it is you can put (keep) in your application's shared preference in private mode and decrypt the file from your application when you want to read it. But I think it some ugly way.

Categories

Resources