[英]How to use Data Protection in Xamarin.iOS?
我正在尝试遵循此 Apple 文档来使用数据保护。 但是,鉴于它位于 Swift 中,我似乎无法将其转换为 C# / Xamarin。
需要明确的是,我不需要整个代码,当然,只需要从哪里开始。 特别是这一行:
try data.write(to: fileURL, options: .completeFileProtection)
我尝试了几种将其翻译成 C# 的选项,但没有奏效。
有关数据保护的官方 Apple 文档可在此处获得。
正如 Oleg 在链接中指出的那样,我将在这里总结一下,以防他们关闭 Xamarin 论坛:
public static void SetFileProtection(string filePath)
{
NSMutableDictionary dict = new NSMutableDictionary ();
var protection = new NSString("NSFileProtectionCompleteUnlessOpen");
dict.Add((new NSString("NSFileProtectionKey") as NSObject), (protection as NSObject));
NSError error;
NSFileManager.DefaultManager.SetAttributes(dict, filePath, out error);
if (error != null)
System.Console.WriteLine("SetFileProtection Error: " + error.Description);
}
您可以使用iExplorer测试功能。 您将看到除非设备受信任,否则无法访问数据。 借助官方文档中的数据保护等级选择适当的保护级别:
(NSFileProtectionComplete):class 密钥受用户密码和设备 UID 派生的密钥保护。 用户锁定设备后不久(10 秒,如果要求密码设置为立即),解密的 class 密钥将被丢弃,导致此 class 中的所有数据无法访问,直到用户再次输入密码或使用 Touch ID 或人脸解锁设备ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.