Lucas Jota
Lucas Jota

Reputation: 1873

Is it possible to access a runtime decrypted file in android?

I want to decrypt a file stored at my app's res folder. This file is distributed with the app, and I'm trying to decrypt it only once during app start.

So far, I've found some answers (this one, for instance) about how to write the decrypted file into sdcard, but won't that file be available to malicious access at the sdcard?

I wish I could write the CipherInputStream into a java.io.InputStream, so I could use it without writing any decrypted data to disk. Is it possible?

Upvotes: 2

Views: 322

Answers (1)

Marcel Krivek
Marcel Krivek

Reputation: 167

I think you want something like this

private InputStream getDecodedInputStream (InputStream eis) {
   Cipher cipher = Cipher.getInstance("your cipher definition");
   cipher.init(Cipher.DECRYPT_MODE, "your keySpec", new IvParameterSpec("your IV parameter spec"));
   InputStream decryptedInputStream = new CipherInputStream(is, cipher);
   return decryptedInputStream;
}

where eis is your encrypted input stream

Upvotes: 1

Related Questions