【问题标题】:How to secure or encrypt video files with NSFileManager?如何使用 NSFileManager 保护或加密视频文件?
【发布时间】:2016-02-15 19:13:25
【问题描述】:

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

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];

【问题讨论】:

    标签: ios objective-c iphone ios7 ios8


    【解决方案1】:

    Apple 已阻止从 App Store Refer this 下载的应用程序访问大部分应用程序目录

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

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

    【讨论】:

      【解决方案2】:

      您可以使用任何加密算法来加密您的数据。 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];
       }
      

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

      【讨论】:

      • 这种情况我们没有使用NSData,我们直接下载视频文件。
      • 下载后会得到文件吗?这将是 NSData。希望你能从 responseObject 或者 operation 对象中得到它
      • 我们预定义了视频下载的路径(目标路径)- AFDownloadRequestOperation *videoDownloadRequest = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:path shouldResume:YES];
      • 你对隐藏 NSDocument 目录有什么想法吗?一些应用程序是安全的 iexplorer-(例如 Lottie dottie)
      • 您无法从 iExplorer 隐藏任何文件夹。唯一的方法是加密数据。
      猜你喜欢
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 2011-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-21
      相关资源
      最近更新 更多