如何使用NSFileManager保护或加密视频文件?

时间:2015-11-14 06:17:20

标签: ios objective-c iphone ios7 ios8

我需要在iOS上的文档目录或(图书馆目录)中保护文件,尤其是视频。我不希望用户可以通过Xcode或iExplorer应用程序下载文档目录中的视频。我需要保护Library目录中的私有内容(或)从服务器下载后如何加密视频文件。请帮帮我。

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@.mp4",videoUrlName]]];
NSString* path = [NSString stringWithFormat:@"%@.mp4",videoName];
AFDownloadRequestOperation *videoDownloadRequest = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:path shouldResume:YES];

[videoDownloadRequest setProgressiveDownloadProgressBlock:^(AFDownloadRequestOperation *operation, NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile)
 {
     float progress = totalBytesReadForFile / (float)totalBytesExpectedToReadForFile;
     NSString *progressMessage = [NSString stringWithFormat:@"%@%@ / %@", @"Downloading...", [self fileSizeStringWithSize:totalBytesReadForFile], [self fileSizeStringWithSize:totalBytesExpectedToReadForFile]];
 }];

[videoDownloadRequest setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
 {
     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Message" message:[NSString stringWithFormat:@"%@ has been added to your Playlist",detailCellView.titleLabel.text] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
     [alertView show];
 }
                                            failure:^(AFHTTPRequestOperation *operation, NSError *error)
 {


 }];
[[NSOperationQueue mainQueue] addOperation:videoDownloadRequest];

2 个答案:

答案 0 :(得分:3)

您可以使用任何加密算法来加密数据。 AES256是最常用的算法之一。

您可以使用这个使用AES https://github.com/RNCryptor/RNCryptor

的优秀包装器

用法也很简单。

[videoDownloadRequest setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
 {
    NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
    NSString *password = @"Secret password";
    NSData *ciphertext = [RNCryptor encryptData:data password:password];

   [data writeToFile:path atomically:YES];
 }

但请记住,真正的安全性在于您保持密钥的安全性(即上述情况下的密码密码)

答案 1 :(得分:0)

Apple已禁止访问从App Store Refer this

下载的应用的大部分Apps目录

我们需要在提交应用之前做一件事

https://developer.apple.com/library/ios/qa/qa1719/_index.html