Reputation: 1298
I think about putting my 1000 lines of db records in class in android in order to better prevent from stealing the sqlite database, which i belive it's a way easier way to solve the issue of stealing instead of using the encrypting the sqlite db. My data will allways be fixed no changes will be made. So i was more interested in how will that react on the speed of the app getting the data from a java class instead of sqlite , or if anyone can show me an example of easy way to encrypt the db, i am also usng SqliteAssistHelper so i don't think i can move my assets folder to the root of my app
Upvotes: 1
Views: 106
Reputation: 2305
Are you familiar with this process sqlcipher?
Take a look at this also: sqlite-encrypt. I think this is a better approach that the one you are asking about.
Upvotes: 0
Reputation: 8978
I'd just encrypt every row that you put put into your database.
usage:
Crypto cr = new Crypto();
cr.generateKey();
byte[] enc = cr.encrypt("some data string"); // enc is your encrypted string
Crypto.java:
public class Cryptooo {
SecretKeySpec key = null;
byte[] ciphertext;
public void generateKey() {
String passphrase = "3xtr3meDiFficUltp@ss";
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("SHA");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
digest.update(passphrase.getBytes());
key = new SecretKeySpec(digest.digest(), 0, 16, "AES");
byte[] keyBytes = key.getEncoded();
}
public byte[] encrypt(String string) {
Cipher aes = null;
try {
aes = Cipher.getInstance("AES/ECB/PKCS5Padding");
aes.init(Cipher.ENCRYPT_MODE, key);
ciphertext = aes.doFinal(string.getBytes());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
}
return ciphertext;
}
public String decrypt(byte[] ciphertext) {
Cipher aes = null;
String cleartext =null;
try {
aes = Cipher.getInstance("AES/ECB/PKCS5Padding");
aes.init(Cipher.DECRYPT_MODE, key);
cleartext = new String(aes.doFinal(ciphertext));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
}
return cleartext;
}
}
Upvotes: 1