I want to decrypt the encrypted apk file in private mode, I know it is possible to decrypt it to a particular location.
Im using the following code to decrypt it to a sdcard.
FileInputStream fis = new FileInputStream("/sdcard/encrypted.apk");
FileOutputStream fos = new FileOutputStream("/sdcard/decrypted.apk");
SecretKeySpec sks = new SecretKeySpec("MyDifficultPassw".getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, sks);
CipherInputStream cis = new CipherInputStream(fis, cipher);
int b;
byte[] d = new byte[8];
while((b = cis.read(d)) != -1) {
fos.write(d, 0, b);
}
fos.flush();
fos.close();
cis.close();
}
But is it possible to decrypt apk file in a private mode…?
It looks like you are mixing things up. MODE_PRIVATE or in detail Context.MODE_PRIVATE is used if you want to create a file in the app’s data directory.
Using MODE_PRIVATE doesn’t make use of encryption at all, it simply sets the file access permissions so that only the app itself can access the file.
On a lot of devices the
/sdcardsection is a separate partition or sd-card formatted with fat32 – which does not support permissions on file-level at all. Therefore MODE_PRIVATE will not work on the path.If you need a FileOutputStream in MODE_PRIVATE you can simply call:
The context is the Context of your App. It will work at least in the app’s private data directory.