Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 views
in Technique[技术] by (71.8m points)

java - using SQLCipher with android shipped sqlite database file

I have a database file reset in the assets file.

How can I use SQLCipher to encrypt the database in android?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is going to be a bit complicated. Since the database file format is different between SQLite and SQLCipher for Android, and since you want to ship an unencrypted database, you will have to do a few things.

First, I'd get SQLiteAssetHelper going, to deliver the unencrypted database to your environment.

Then, use standard SQLCipher for Android to create an empty-but-encrypted database.

Next, you will need to implement the code to copy the data out of the packaged-but-unencrypted database and insert it into the empty-but-encrypted database.

Once that is all done, you can close and delete the packaged-but-unencrypted database and just use the encrypted one.

This might make a useful extension to SQLiteAssetHelper, someday...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...