如何将密码传递给 sqlcipher ContentProvider

How to pass password to sqlcipher ContentProvider

我正在尝试在我的应用程序中实施一个安全数据库,要求用户在应用程序启动时输入密码。他们输入的密码用于解密包含他们数据的 sqlcipher 数据库。我难过的部分是如何将密码传递给内容提供者。

现在我将密码临时存储在共享首选项中,供我的内容提供者访问它,然后在我的 MainActivity 中调用 onStop 时删除共享首选项。但是,一旦我引入多个活动,这似乎过于复杂。是否有更有效的方法来为当前应用程序会话设置我的 sqlcipher ContentProvider 的密码?

The part that I am stumped on is how to pass the password to the content provider.

选项 #1:不要使用 ContentProvider

选项 #2:在 ContentResolver 上使用 call(),这又会在您的 ContentProvider 上调用 call()。这是一个特别的通信路径,您基本上可以在其中定义含义。您可以将其用作 "set passphrase" 类型的机制,其中您的 UI 层收集密码并通过 call() 将其传送给提供商。请注意,这需要 minSdkVersion 为 11 或更高。

在这两个中,我强烈推荐选项 #1。

Right now I am storing the password temporarily in shared preferences for my contentprovider to access it and then deleting the sharedpreference when onStop is called in my MainActivity.

这会将密码短语以明文形式写入磁盘。 请不要这样做