0

I need to secure files in document directory or (Library directory) on iOS especially videos. I don't want user can download videos in document directory by Xcode or iExplorer app. I need to secure the private content inside of the Library directory (or) how to encrypt video file after downloading from server. Please help me on this.

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];
Ramkumar Paulraj
  • 1,841
  • 2
  • 20
  • 40

2 Answers2

3

You can use any of the encryption algorithms for encrypting your data. AES256 is one of the most common algorithms used.

You can make use of this excellent wrapper which uses AES https://github.com/RNCryptor/RNCryptor

The usage is also pretty much straight forward.

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

But keep in mind that the real security lies on how secure you are keeping the key(i.e the Secret password in the above case)

ipraba
  • 16,485
  • 4
  • 59
  • 58
  • We didn't use NSData for this conditions , We are downloading video files straightly. – Ramkumar Paulraj Nov 14 '15 at 06:31
  • after downloading you will get the file right? Which will be of NSData. I hope you will get it from responseObject or operation object – ipraba Nov 14 '15 at 06:33
  • We predefine the PATH For video downloading (target path)- AFDownloadRequestOperation *videoDownloadRequest = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:path shouldResume:YES]; – Ramkumar Paulraj Nov 14 '15 at 06:34
  • Are you have any idea for hide the NSDocument directory . Some of the applications are secure from the iexplorer- (ex. Lottie dottie) – Ramkumar Paulraj Nov 14 '15 at 06:38
  • responseObject :: /var/mobile/Containers/Data/Application/B6F58F7C-1C6C-4FCD-B1D1-88546601EC4A/Library/Video1, Video1.mp4 – Ramkumar Paulraj Nov 14 '15 at 06:40
  • how to hide NSDocumentDirectory from iExplorer ? I want to protect file from iExplorer , encryption method is not supported for my app because NSData can't play with AVPlayer. So I need good solution for this. Some of the applications are secure from the iexplorer- (ex. Lottie dottie) – Ramkumar Paulraj Nov 14 '15 at 10:48
  • 1
    You cannot hide any folder from iExplorer. Only way is to Encrypt the data. – ipraba Nov 14 '15 at 10:51
  • But I can't play NSData with AVPlayer, If I want to play, again I should save decrypted file into NSFileManager. But it is not secured... do u have any idea for this – Ramkumar Paulraj Nov 14 '15 at 11:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/95119/discussion-between-ram-and-iprabu). – Ramkumar Paulraj Nov 14 '15 at 11:12
1

Apple has blocked access to most of the Apps directory for apps downloaded from the App Store Refer this

We need to do one thing before the app submission

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

Ramkumar Paulraj
  • 1,841
  • 2
  • 20
  • 40