How to test if Core Data SQLlite file is encrypted?
<p>Core Data seems to be encrypted by default when device is locked but only before the first unlock.</p>

<p>From <a href="https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS5.html#//apple_ref/doc/uid/TP30915195-SW54" rel="nofollow noreferrer">apple docs</a></p>

<blockquote>
  <p>For apps built for iOS 5.0 or later, persistent stores now store data
  by default in an encrypted format on disk. The default protection
  level prevents access to the data until after the user unlocks the
  device for the first time.</p>
</blockquote>

<p>So I set it up to get encrypted whenever the device is locked. The encryption settings for the SQLite file are set before  returning the _persistentStoreCoordinator like so:</p>

<pre><code>NSDictionary *fileAttributes = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];

    if (![[NSFileManager defaultManager] setAttributes:fileAttributes ofItemAtPath:storeURL.path error:&amp;error]) {
        //Handle error
    }
return _persistentStoreCoordinator;
</code></pre>

<p>Code is from <a href="https://nickharris.wordpress.com/2010/07/14/core-data-and-enterprise-iphone-applications-protecting-your-data/" rel="nofollow noreferrer">here</a>.</p>

<p>I would like to test if the file is really encrypted.</p>

<p>What I did is lock the device and download the app container using Xcode->Window->Devices. However the file is not shown in the container. If I do the same when the device is unlocked I can then find it in the container. Why is that? More importantly can I test to see that the file gets encrypted when the phone is locked or it being missing is proof enough.</p>

<hr>

<p><strong>EDIT</strong>: A better setting up encryption for Core Data per this <a href="https://stackoverflow.com/a/23203728">answer</a> suggestion would be:</p>

<pre><code>NSDictionary *storeOptions = @{NSPersistentStoreFileProtectionKey: NSFileProtectionComplete};
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:storeOptions error:&amp;error]){
    //handle error
}
</code></pre>