Owen
Owen

Reputation: 23

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

Upvotes: 0

Views: 138

Answers (1)

chiastic-security
chiastic-security

Reputation: 20520

If you want to do this properly, here are a few tips:

  1. 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.
  2. 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.
  3. Don't store the decryption key!
  4. 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.
  5. AES with a 128-bit key will do you fine.

Upvotes: 1

Related Questions