Android, key -> value 结构安全存储,不可修改

Android, key -> value structure stored safely, not modifiable

我想存储数据的键->值结构,例如

2354235 => string1
3453453 => string2

结构必须在构建时定义,并且在运行时不可修改(出于安全原因)。它必须安全存储(只能由应用程序读取)。将其存储在源代码和 sqlite 数据库中是不可接受的。还有其他想法吗?

你在问两件事:

1) 在构建时,您可以将其存储在代码或数据库之外的位置。 2) 如何让它只能被应用读取。

对于1),我建议你直接使用加密的raw文件(放在/res/raw中)。它们无法修改,可以只是 CSV 或 JSON。检查 javax.crypto 包是否有必要的 类 进行加密。

对于 2),这取决于您希望它有多安全。您可以使用安全连接从服务器下载解密密钥,但您需要确保连接到服务器的确实是您的应用程序。您可以使用 here 中描述的内容在服务器中验证您的应用程序:

Summary

Doing this is a multi-step process, which I’ll outline in full, but here’s the short version: You use the GoogleAuthUtil class, available through Google Play services, to retrieve a string called an “ID Token”. You send the token to your back end and your back end can use it to quickly and cheaply verify which app sent it and who was using the app.