SQLite Context.MODE_PRIVATE

I want to know:

Is it possible to use Context.MODE_PRIVATE in SQLite when creating a database to protect against unwanted access to the database.

I have no google example.
How to use this Context.MODE_PRIVATE in the database.
Please help me. Indicate any link or sample.

In THIS LINK they talk about the file. therefore, the database is also a file.

How can I implement this?

+6
source share
3 answers

As mentioned earlier, SQLite databases in internal storage are private by default. But, as others have mentioned, access to your file has always been your root phone.

Rather, you can use any encryption algorithm to save data to the database, which will help you limit readability if the attacker does not know the encryption algorithm.

You cannot set the "Context.MODE_PRIVATE" flag in SQLite.

0
source

When creating a database, it is useful to use the following syntax

 openOrCreateDatabase(String path, int mode, SQLiteDatabase.CursorFactory factory) 

For instance,

 openOrCreateDatabase("StudentDB",Context.MODE_PRIVATE,null); 

See my tutorial on this site.

0
source

Option 1 : use SQLcipher .

Option 2 : The safest method ever is no chance to hack. This is not perfect, but better than nothing.

1) Insert data using this function:

 public static String getEncryptedString(String message) { String cipherText = null; try { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(("YOUR-SECURE-PASSWORD-KEY").getBytes(), "AES")); byte[] bytes = cipher.doFinal(message.getBytes()); cipherText = Base64.encodeToString(bytes, Base64.DEFAULT); } catch(Exception ex) { cipherText = "Error in encryption"; Log.e(TAG , ex.getMessage()); ex.printStackTrace(); } return cipherText; } 

2) Get data from the database and pass functions to this parameter:

 //This function returns output string public static String getDecryptedString(String encoded) { String decryptString = null; try { byte[] bytes = Base64.decode(encoded, Base64.DEFAULT); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(("YOUR-SECURE-PASSWORD-KEY").getBytes() , "AES")); decryptString = new String(cipher.doFinal(bytes), "UTF-8"); } catch(Exception ex) { decryptString = "Error in decryption"; ex.printStackTrace(); } return decryptString; } 

3) The advantages of these methods: - It is impossible to decrypt without the correct key. - AES Encryption is a very secure encryption method.

4) Save the AES key in a c ++ file.

0
source

All Articles