【问题标题】:Android: Room: no encryption and security?Android:房间:没有加密和安全性?
【发布时间】:2018-02-15 04:04:03
【问题描述】:

现在我正在使用 OrmLite 而不是带有 SQLCipher 的 SQLite。 难道真的没有办法保护Room数据库不被读取???

【问题讨论】:

  • 见android.arch.persistence.db.SupportSQLiteOpenHelper

标签: android android-room


【解决方案1】:

Room 默认将数据存储在应用程序的内部存储中,任何 root 用户都可以访问。

如果您需要一些安全性,您需要使用像 cwac-saferoom 这样的加密库。

【讨论】:

  • 听起来像拐杖,我不敢相信谷歌没有考虑过这个问题
  • 房间工程师针对一般用例进行了优化。添加加密肯定会增加库大小并影响性能。幸运的是,有人为此制作了易于使用的 lib。
  • 这与库大小无关。它可能是分离的依赖关系。
  • @android51130:“听起来像拐杖”——他们专门设计了 Room 以使用支持数据库 API 与其数据库集成。这个想法是其他方可以提供他们自己的 API 实现。我现在正在通过 CWAC-SafeRoom 这样做,以提供使用 SQLCipher for Android 的支持数据库 API 实现。还有I am working with Zetetic to move this support database API implementation directly into SQLCipher for Android.
  • @qbait:我对“稳定”没有真正客观的衡量标准。如果你的意思是1.0.0,我现在在1.0.0-alpha3,除非有人发现漏洞,否则1.0.0 将在月底发布。
【解决方案2】:

Android 的 SQLCipher 现在直接支持 Room。你可以找到文档here

因此,@CommonsWare 将不再积极开发cwac-saferoom,并建议使用 SQLCipher 的支持

【讨论】:

  • 现在我正在使用 Realm 和开箱即用的加密和最简单的查询构建(对我而言),对象没有内存分配(可以直接从磁盘延迟加载到 pagedList存储),但无论如何,这真的很酷,谢谢你的信息!
  • SQLCipher 库在某些运行 android 5(如 oppo)的设备上存在问题 :(
【解决方案3】:

Android Room DB 明确不支持加密。一个典型的 未加密的 SQLite 数据库。您可以将 SQLCipher for Android 与 Room 或 androidx.sqlite API 的其他使用者来保护您的数据 存储在 sqlite 数据库中。 QLipher 有一个SupportFactory 类在 可用于配置 Room 的 net.sqlcipher.database 包 使用适用于 Android 的 SQLCipher。查看标准 SQLite 数据库的 hexdumps 和一个实现 SQLCipher。

~ sjlombardo$ hexdump -C sqlite.db
00000000 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 |SQLite format 3.|
…
000003c0 65 74 32 74 32 03 43 52 45 41 54 45 20 54 41 42 |et2t2.CREATE TAB|
000003d0 4c 45 20 74 32 28 61 2c 62 29 24 01 06 17 11 11 |LE t2(a,b)$…..|
…
000007e0 20 74 68 65 20 73 68 6f 77 15 01 03 01 2f 01 6f | the show…./.o|
000007f0 6e 65 20 66 6f 72 20 74 68 65 20 6d 6f 6e 65 79 |ne for the money|

~ $ sqlite3 sqlcipher.db
sqlite> PRAGMA KEY=’test123′;
sqlite> CREATE TABLE t1(a,b);
sqlite> INSERT INTO t1(a,b) VALUES (‘one for the money’, ‘two for the show’);
sqlite> .quit

~ $ hexdump -C sqlcipher.db
00000000 84 d1 36 18 eb b5 82 90 c4 70 0d ee 43 cb 61 87 |.?6.?..?p.?C?a.|
00000010 91 42 3c cd 55 24 ab c6 c4 1d c6 67 b4 e3 96 bb |.B?..?|
00000bf0 8e 99 ee 28 23 43 ab a4 97 cd 63 42 8a 8e 7c c6 |..?(#C??.?cB..|?|

~ $ sqlite3 sqlcipher.db
sqlite> SELECT * FROM t1;
Error: file is encrypted or is not a database

https://github.com/sqlcipher/android-database-sqlcipher

【讨论】:

  • 您是否可以在此答案中添加更多信息或清晰度?
猜你喜欢
  • 1970-01-01
  • 2021-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-23
  • 1970-01-01
  • 2016-04-06
  • 1970-01-01
相关资源
最近更新 更多