title: How to protect data in Documents directory with encryption?
body: <p>I have an app that downloads several pdfs and images and save them in the <code>Documents</code> directory. I need these files to be protected by everyone who try to access them via tools like iExplorer. I found the iOS Security Guide and I enabled the <code>Data Protection</code> capability. I then tried to create a txt file in this way :</p>
  
  <pre><code>let documentsPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).first!
  let filePath = documentsPath + "/hello.txt"
  
  FileManager.default.createFile(atPath: filePath, contents: Data.init(base64Encoded: "HELLOOOOOOOO"), attributes: [kCFURLFileProtectionKey as String: FileProtectionType.complete])
  </code></pre>
  
  <p>Then, I tried to use iExplorer to access the txt file and I was able to do it as for any other non protected file. I did having my iPhone unlocked and also locked and after wait up to 5 minutes. The files were there accessible without any problem. I really need to know if there's a way to make them unaccessible, at least when device is locked.</p>
  
  <p>Another solution I was thinking about is to encrypt the files in the Documents folder with a custom algorithm, but in this way in case of big files we lose the speed in opening the file because everytime we need to decrypt it and this requires an amount of time that depends on the size of the file itself. </p>
  
  <p>Suggestions?</p>