2014-10-20 30 views
2

我想解密存儲在我的應用程序的res文件夾中的文件。此文件隨應用程序一起分發,我試圖在應用程序啓動時僅對其解密一次。是否有可能在android中訪問運行時解密文件?

到目前爲止,我已經找到了一些關於如何將解密文件寫入SD卡的答案(this one, for instance),但是該文件是否可用於在SD卡上進行惡意訪問?

我希望我可以將CipherInputStream寫入java.io.InputStream,所以我可以在不將任何解密數據寫入磁盤的情況下使用它。可能嗎?

回答

1

我想你想是這樣的

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; 
} 

其中EIS是加密的輸入流

+0

我看到'CipherInputStream'延伸'InputStream',不就意味着'decryptedInputStream'被解密?我不應該調用'CipherInputStream.read()'來實際解密數據嗎? – 2014-10-21 12:11:00

+0

是的,它意味着正在解密'decryptedInputStream' – 2014-10-21 12:17:37

+0

那麼,我接受你的答案。但我仍然無法使用解密的數據。 [這裏](http://stackoverflow.com/questions/26473519/decrypt-self-signed-certificate-throws-ioexception-wrong-version-of-key-store)是一個關於我的問題更詳細的問題,如果你是感興趣。感謝您的關注! – 2014-10-21 12:39:31

相關問題