SD card files encryption API
android, android-sdcard, encryption, filesystems
Solution
public byte[] keyGen() throws NoSuchAlgorithmException {
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(192);
return keyGenerator.generateKey().getEncoded();
}
you need to store key in your app
public byte[] encript(byte[] dataToEncrypt, byte[] key)
throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
//I'm using AES encription
Cipher c = Cipher.getInstance("AES");
SecretKeySpec k = new SecretKeySpec(key, "AES");
c.init(Cipher.ENCRYPT_MODE, k);
return c.doFinal(dataToEncrypt);
}
public byte[] decript(byte[] encryptedData, byte[] key)
throws NoSuchAlgorithmException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
Cipher c = Cipher.getInstance("AES");
SecretKeySpec k = new SecretKeySpec(key, "AES");
c.init(Cipher.DECRYPT_MODE, k);
return c.doFinal(encryptedData);
}
Problem
I would like if someone could tell me a way to make folder on the SD card to be hidden/invisible/encrypted when the device connected to usb storage mode / inner file browsing app on the device. I need also the ability to access this files from my android application (only to read them if it makes any different..) I know about some file encryption apps like SecretVault pro, but apps like this don't have API for developers, which allow to control the encrypted/decrepited state progrematically.