ios - 如何使用 Apple 的数据保护 API 加密我的数据?

标签 ios iphone swift encryption data-protection

我想加密用户手机上保存的所有数据,除非通知需要这些数据。在查看苹果的文档后,NSFileProtectionCompleteUnlessOpen 看起来是我需要的通知中使用的数据,NSFileProtectionComplete 应该为通知不需要的数据做。

我知道这些是 NSFileManager 中的属性,但我不熟悉此类,不想弄错。我已经搜索了 createDirectory 函数调用,它允许我在创建新文件时更改 fileProtectionAttributes,但看起来我们的文件来自不同的来源,所以我需要一种从现有目录设置 fileProtection 属性的方法。

我正在使用 swift 2 和 iOS 8

let files = NSFileManager.defaultManager().enumeratorAtURL(CallIn.DocumentDirectoryURL, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions(), errorHandler: nil)

最佳答案

启用数据保护

enter image description here

使用您选择的加密类型创建权利 plist。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>DataProtectionClass</key>
    <string>NSFileProtectionComplete</string>
</dict>
</plist>

关于ios - 如何使用 Apple 的数据保护 API 加密我的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36548482/

相关文章:

ios - CBPeripheralManager 限制

iOS 动画容器 View 使它们不响应触摸事件

ios - imo、whatsapp 和 skype 等 iPhone 锁定时如何实现应用程序调用?

arrays - 字符串数组到 Int8 数组字节类型转换

ios - UIPageViewController 在移动到第三个 View Controller 后取消分配第一个 View Controller ?

ios - NSPredicate : to-Many relationship with date iOS

iphone - 如何激活后台应用程序以与附近的另一个设备提供 TCP/IP 流服务?

iphone - 为 iPhone 本地化货币

ios - 为什么我的 Print 语句没有被执行?

swift - 使用 `__FUNCTION__` 作为 `objc_getAssociatedObject` 的 key 是否可以