问题描述
确定(名义上的)SqlCipher 数据库是否实际加密(在 iOS 中)的最干净和最有效的方法是什么.请注意,此处 的技术不适用于 SqlCipher——无论是否加密,SQLite 格式 3"前缀都是有效的.
What would be the cleanest and most efficient way to determine if a (nominally) SqlCipher database is actually encrypted (in iOS). Note that the technique here does not work with SqlCipher -- the "SQLite format 3" prefix is valid whether encrypted or not.
显而易见的方法是打开数据库,尝试对其进行操作,然后查看返回码是否为 SQLITE_NOTADB.但不清楚要尝试什么操作.
The obvious way is to open the DB, attempt an operation on it, and see if the return code is SQLITE_NOTADB. But it's not clear what operation to attempt.
添加:嗯...显然某些版本的 SqlCipher 不保留文件前缀.
Added: Hmmm... Apparently SOME versions of SqlCipher don't preserve the file prefix.
推荐答案
SQLCipher 在文件的前 16 个字节中存储唯一的随机盐.如果您获得 SQLite 格式 3\000
并且内容仍然是加密的,则它可能不是 SQLCipher 加密的数据库.
SQLCipher stores a unique random salt in the first 16 bytes of the file. If you are getting SQLite format 3\000
and the content is still encrypted, it is likely not a SQLCipher encrypted database.
最后,您还可以发出 hexdump -C YourDatabase.db
并检查输出,纯文本数据库将包含输出中的可见模式.
Finally, you could also issue a hexdump -C YourDatabase.db
and inspect the output, a plain text database will contain a visible schema from the output.
这篇关于确定 SqlCipher DB 是否加密的最简洁方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!