2

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.

2
  • Do you control the C code at all? You will probably need to modify the API for what you want to accomplish Commented Oct 29, 2012 at 19:19
  • Yes, I have control over the C code. Commented Oct 29, 2012 at 19:40

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help! I will try these options out. I was just having some trouble conceptualizing what to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.