I have an Android project that uses a C library to parse out a certain type of file. I am working on adding encryption to the project using AES and CipherInputStreams and CipherOutputStreams. The issue is that the Java code passes a file name and descriptor to the C library, then the C library performs the file reads. As is, if the file is stored encrypted, the C library just reads the file as garbage. Is there a way to pass a CipherInputStream down to the C code so that the decryption is handled? Or should I just decrypt the file in Java and store it in private storage as plaintext and then send a file descriptor for that down to the C code? That seems relatively inefficient.
Share
Since you can modify the C code, I would recommend you build the encryption layer directly in there. This way your Java code won’t care if it’s on top of an encrypted file or not.
If you do want to have that encryption logic in your Java code, then I think you’ll need to do the byte[] reading in Java and pass each result of InputStream.read to your C code. You’ll probably need to change your API for this and need a way to tell the C code when you’re done.