Data Protection

本文介绍了iOS应用中如何使用内置加密硬件对文件进行加密存储,包括通过设置不同级别的数据保护来确保文件的安全性。提供了实现文件加密的具体代码示例。

* It looks no use for the toolkid to export the files(set protection by setting or code), file exported is unencrypted, even the device is lock.

* If passcode is lock, it can't copy out or view by toolkid.

* if passcode is lock ,we can't read the file after refresh toolkid,(both mode)

 

https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/AddingCapabilities/AddingCapabilities.html

 

 

Enabling Data Protection (iOS Only)

Data protection adds a level of security to files stored on disk by your iOS app. Data protection uses the built-in encryption hardware present on specific devices to store files in an encrypted format on disk. Your app needs to be provisioned to use data protection.

To enable data protection

  1. In the Capabilities pane, if Data Protection isn’t enabled, select the switch in the Data Protection row.

    ../Art/4_enabledataprotection_2x.png
  2. If a dialog appears asking whether Xcode should request a development certificate on your behalf, click Request.

The default level of protection is complete protection, in which files are encrypted and inaccessible when the device is locked. You can programmatically set the level of protection for files created by your app, as described in Protecting Data Using On-Disk Encryption in App Programming Guide for iOS.

 

- (IBAction)doWriteProtectedData:(id)sender{
    NSString *s = @"Hello2";
    NSError *err = NULL;
    NSString *sPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    sPath = [sPath stringByAppendingPathComponent:@"a.txt"];
    [s writeToFile:sPath atomically:YES encoding:NSUTF8StringEncoding error:&err];
    if(err){
        NSLog(@"err:%@",err.description);
    }
    
    err = NULL;
    NSDictionary *dicAtt = @{NSFileProtectionKey:NSFileProtectionComplete};
    [[NSFileManager defaultManager] setAttributes:dicAtt ofItemAtPath:sPath error:&err];
    if(err){
        NSLog(@"err:%@",err.description);
    }
    NSLog(@"Write to %@",sPath);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值