I have an application which writes and reads from a specific file on the SD card.
What i would like is a way to encrypt the whole SD card or a minimum of That specific folder. So if the phone is stolen no one can read the content of that folder.
However, i also want the application to still be able to interact with the folder and the password isn't required until someone looks at the folder specifically (using astro etc) or inserts it into a PC to view.
Is this possible? thanks
You'll need to do this manually, look into javax.crypto for getting the crypto bit done relatively painlessly.
This won't be possible with an ordinary (unmodified) android system (I assume).
If you are talking about your own app - you could implement your own file level encryption in your application.
For everything else, I'd say you need to modify android to include some kind of encrypted file system and the relevant UI for it.
Related
I want to develop an application which lets user protect their files / folders . It is very much the same as existing apps where user can select the files to be hidden and those files can be accessed only from my app which is password protected.
I got enough resources about the encryption algorithm.
Here my doubt is :
where should i keep my encrypted files. It should be within my app folder. But this folder if i create on phones internal storage, will that not lead to memory restrictions. My app let user to add images / videos or any other file to protection. If i keep the folder on the sd card, the questions are it will restrict app to be run on only mobiles with sd card . Also the content of sd card can be accessed by others ( i am right here ? )
The next doubt is that i see most of those apps i see if i remove protection it is restored in its previous folder. How is it achieved . Is it like keep mapping table an duse that to restore ?
Please help me with answers for my questions. Thanks a lot for your time and help
According to my investigations of the same problem, there is no built-in encrypted storage in Android system. Hence, I'd recommend you following approach:
Encrypt file content with any algorithm. See here(1), here(2) and here(3).
Use MODE_PRIVATE when creating file with, for example, openFileOutput(String, int)
I am messing around with node.js on Android through this project, and I need a way to deploy js files to a private directory (to hide the source code, and prevent users from tampering) which also physically exists on the filesystem (an apparent requirement for node.js).
Is it correct to place my javascript files in /data/data/com.skabbes.android/node_modules? And if not, what would be the correct way to accomplish my goal?
Well, if you are wanting to store something on the internal storage, it is not recommended to use an absolute path like /data/data/..../ because while that may be the correct path, it can potentially change with different devices or different Android versions because /data/data/ the internal file structure is not specified in official Android documentation.
I also want to point out that even if you are storing information in the /data/ directory it is still possible that someone could access it if they have a rooted phone.
But, what you should do is see This. That will save information on the internal storage of the device and neither the user nor other apps can access the files you save with that method unless the device is rooted.
You should use the getFilesDir() method of Context which basically abstracts the absolute path.
It will most probably be something like /data/data/<package-name>/files but it's a better way to make sure your app is compatible with all versions of Android and all devices.
So I'm making this android application, that needs to read data from user-provided CSV files.
The CSV files are more confortably edited on a desktop computer, so I have no editor in the app, which is 'read-only' ; I assume there is a file on the phone's SD card.
Following the Data Storage documentation, I managed to write a dumb version that reads the file from external storage, hard coding the folder location relative to whetever getExternalStorageDirectory returns. So for the moment I have :
private static final String CSV_FILE = "/Android/foo/bar.csv"
...
File f = new File(Environment.getExternalStorageDirectory(), CSV_FILE);
Then I would connect my phone to a PC, create a "foo" folder in the "/Android" folder (that exists on my phone), copy the "bar.csv" file, and everythings goes fine.
Now obviously, this is not acceptable if I want to distribute the application. So I have a few questions :
The natural solution is to softcode the file location, and in any other system I would rely on a built-in "file manager" or something, to let the user browse to the right file.
Surprisingly I could not find such a control, and it seems like there are lots of third-party File Browser app. Does it mean it is not "customary" to ask a user to choose a file on their phone ? Should I write my own 'file browser' ?
Are there conventions about how I should name my "foo" dir ? I've seen apps creating dir with a name that looks like a java package, am I mistaking it with internal storage ?
There is also a getExternalStoragePublicDirectory method that takes a "directory type' constants. In my situation, would it make 'sense' to assume the file is in DIRECTORY_DOWNLOADS ? (or in some subfolder of DIRECTORY_DOWNLOADS ?)
Should I bother about how a lambda user will put a file on their phone ? To me plugging the phone on my PC is simple enough, but is that really easy on all droids ?
Sorry if all of that sounds trivial, just trying to clear my mind before doing something stupid.
Thanks.
Does it mean it is not "customary" to ask a user to choose a file on their phone ?
Correct. Android, like iOS, tries to get away from "files" as much as possible.
Should I write my own 'file browser' ?
There are certainly plenty of third-party applications for file browsing, some of which support ACTION_PICK or similar operations (e.g., OI File Manager). I will be surprised if nobody has written a reusable component for this.
Are there conventions about how I should name my "foo" dir ? I've seen apps creating dir with a name that looks like a java package, am I mistaking it with internal storage ?
No, you are probably seeing the results of getExternalFilesDir(). If you are only supporting API Level 8 or higher, I'd just use that. If you are supporting earlier versions of Android, you might consider finding out the appropriate directory for your app that would be used via getExternalFilesDir() and use that "manually" for older Android versions.
There is also a getExternalStoragePublicDirectory method that takes a "directory type' constants. In my situation, would it make 'sense' to assume the file is in DIRECTORY_DOWNLOADS ? (or in some subfolder of DIRECTORY_DOWNLOADS ?)
That is for downloads -- more accurately, things the user downloaded that they want to hang onto independent of any installed app. It does not sound like this fits your scenario.
Should I bother about how a lambda user will put a file on their phone ?
What is a "lambda user"? To quote the Bard, "but, for mine own part, it was Greek to me" :-)
To me plugging the phone on my PC is simple enough, but is that really easy on all droids ?
It is somewhat more painful on Android 3.x and higher, as Android moves away from USB Mass Storage mode (think USB thumb drives) and to MTP (think MP3 player) for its USB file transfer protocol. While this has overall benefits, it is annoying for OS X and Linux users, as neither have built-in MTP support. Also, it assumes the user has a USB cable handy. Your overall setup also assumes the user has a desktop OS handy.
Nowadays, more developers would probably go the route of creating a Web app rather than a desktop app, and syncing the data to the device over the Internet. This eliminates the need for fussing with cables and does not tie the user to one specific "desktop" machine for data entry. It does, however, require Internet access, which may or may not be suitable for your situation.
hello guys i need small help in understanding file system of android
Now in windows for example we create files using paths like "c:/mytextfile.txt" or "c:/folder/mytextfile.txt".Now how can i access files and folders in android i mean whats the path like.
Does the phone support file browser instead of relying on third party apps??
Android does not have a native file browser, but there are numerous third-party ones (Astro comes to mind). The filesystem of Android is that of Linux; the path separator is / and the FS grows from a single root called /. So, you have your app packages under /data/apps, and so forth. Unless the phone is jailbroken ("rooted"), you won't get to see the whole filesystem - permissions get in the way. This applies to all Android applications, they are sandboxed - that is, they don't get access the whole filesystem. There are API calls to get the path to the current application's sandbox directory.
I am creating android application which contains DB that needs to be hidden(not able to access by the user)in the SD Card. Can anyone tell me how to do this?
Any file stored on the SD card is accessible both by applications running on the phone, and by users who have mounted the SD card (both while it's in the phone and otherwise).
You can change the file properties to make it 'hidden', but it will still be easily found. There is no way to make a file on a public partition like an SD Card 'secure' in the manner you describe - users will always be able to copy, delete, and potentially change the file.
The best solution to your problem is to look into ways to encrypt your database to record it securely. You won't be able to prevent users from deleting or copying the file, but you should be able to make it difficult for them to read data from it or modify its contents.
For an easy solution, just prefix the db file with a . (like .dbfile). This will hide the file on Linux based systems, including android.
I am assuming that you want to hide the file to prevent users from accidentally deleting/changing it.
SD cards cannot be secured in the fashion you seek.
just name the file start by ."Dot"... ".myFolder/.myfile"
You can create a folder whose name starts with a dot(.) example (.dbfiles) android See these folders as configuration folder and do not show content of these folder in applications like gallery,music player...You can see these folders with advance file explorer like Es File explorer
Sdcard you cant't! Internal app data partition is the place for you.