1

I have a single string I need to store securely. I read about SQLite encryption, but I don't want to create a DB for only one piece of data. Is there another way to secure it? Thanks.

user940016
  • 2,878
  • 7
  • 35
  • 56

2 Answers2

2

You can use SharedPreference. Encrypt the string using any encryption method and save it in your app's SharedPreference. When you need to use it just retrieve it, decrypt it and use it. Hope it would help.

Take a look here.

Varundroid
  • 9,135
  • 14
  • 63
  • 93
  • But then how do I store the key I used? – user940016 Jul 28 '12 at 13:11
  • Save your key in SharedPreference as well. As you don't want to use Database so you don't have much options that can hold the values securely. SharedPreference are secured enough. – Varundroid Jul 28 '12 at 13:20
  • You can use an internal file system as well but i don't think that it's as secured as SharedPreference cuz data stored in SharedPreference is only accessible from inside your app's code. – Varundroid Jul 28 '12 at 13:24
  • 1
    But SharedPreference might still be hacked and then the hacker will be able to read the key. Even if it's only accessible from my application, it's still stored somewhere on the device... – user940016 Jul 28 '12 at 14:02
  • Who gave you this Idea that SharedPreference can be hacked easily. If SharedPreference can be hacked then Database can also be hacked. If you doubt SharedPreference then you should use Database. Sqlite is a really light it won't give your App an extra overhead. If you are going to perform heavy database then use AsyncTask. You can take a look here http://stackoverflow.com/questions/6276358/pros-and-cons-of-sqlite-and-shared-preferences as well. SharedPreference and SQLite are equally safe. – Varundroid Jul 29 '12 at 04:12
1

You can encrypt your string with any of the many options available in Java, and store it on the Internal Storage or in the Shared Preferences

Something I found on encryption: Encrypt and decrypt a String in java

Amdroid Storage Options: http://developer.android.com/guide/topics/data/data-storage.html

Community
  • 1
  • 1
Hans Hohenfeld
  • 1,729
  • 11
  • 14