Jaythaking
Jaythaking

Reputation: 2102

Reading encrypted blob file from database without storing it

I want to store pdf, word, excel (...) files into the sqlite Database as BLOB data and then, retrieve it to be open using a third party application.

Because those files are confidential, I don't want them to be stored in the phone while reading them. (If the phone is stolen, I don't want stranger to have access to the file)

What are my options?

Upvotes: 0

Views: 544

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007296

I don't want them to be stored in the phone while reading them

Technically, you do not have control over that. The third-party app is welcome to do whatever it wants with the data, which includes saving it to a file, sharing it over the Internet, etc.

You are welcome to write a ContentProvider that streams your documents in response to openFile(). In your case, since the content is not a file, you would need to use a ParcelFileDescriptor pipe, so you can write your data to an OutputStream. This sample project demonstrates the basic technique, though I am serving a PDF from assets.

I would not be surprised if you run into problems with larger documents, though. The client app may want to seek forwards and backwards in the stream, and pipes do not result in seekable streams.

Upvotes: 1

Related Questions