ios不强制执行加密安全性参数

时间:2018-04-19 15:50:05

标签: ios swift

我试图加密我的ios应用中的某些文件,以防止拥有越狱手机的人访问我应用的文件内容。

我正在使用Apple文档中的Encrypting Your App's Fileshttps://developer.apple.com/documentation/uikit/core_app/protecting_the_user_s_privacy/encrypting_your_app_s_files

所以我用这个来写文件

let data = "hello".data(using: .unicode)!
try! data.write(to: fileURL, options: .completeFileProtection)

根据文档,此选项意味着:

  

完整。只有在设备解锁时才能访问该文件。

所以在AppDelegate方法的applicationDidEnterBackground中,我添加了等待5秒的代码(为设备提供完全锁定的时间)并访问文件:

Thread.sleep(forTimeInterval: 5.0)
let data = try! Data(contentsOf: fileURL)
print(String(data: data, encoding: .unicode)!)

我在实际设备上尝试了这个,锁定了手机,等了5秒钟,数据读好了!我期待阅读失败。

我错过了什么?

PS:这种方法是否真的保证了越狱设备文件在文件系统中不可读?

1 个答案:

答案 0 :(得分:0)

我发现有一个设置可以在project -> capabilities下启用数据保护。它已关闭,因此数据未加密:

enter image description here