If I'm about to sell my iPhone 5, is there a way to make sure that the buyer won't be able to recover anything from my data? Both data that has been recently deleted and data that has been deleted long time ago.
Using the built-in wipe function is fine for casual use/reselling of a device.
- Settings -> General -> Reset -> Erase All Content and Settings
However it is not necessarily proof against forensic data recovery. (It could be, but I don't know whether it is. Typically for most devices it wouldn't be).
On the other hand, if your life - or anyone else's - is at stake, you should destroy the device, not resell it. Grind the device to dust. Heating the whole thing in a charcoal fire to a red heat should work too. (Be careful - the battery will probably explode.)
Typically, deletion involves rewriting bookkeeping data to mark portions of the disk as unused. It doesn't actually overwrite the data. To be secure you must overwrite the data or specialised software or hardware can read the data directly bypassing the bookkeeping functionality.
To achieve this you have to write data until the device is full. Depending on the filesystem it may even be more complicated than that. But for a poor-man's version, you could use the system erase function, then fill it up with files using the PC connection. Then wipe it again. You will have to do that several times to beat the wear-levelling algorithm.
This will be better than the standard system wipe, but still will not be perfect.
If you need a perfect wipe, complete destruction is the only way I would recommend.
So, if you use the built-in wipe function mentioned above: Settings -> General -> Reset -> Erase All Content and Settings, it leaves behind a .obliterated file which proves that the device was wiped. It's time stamp also specifies the date/time of this action.
The only way I can think of doing this is to enable the hardware backed phone encryption along with a STRONG passkey. I think you can achieve this by Settings > General > Passcode. This should help you with this - http://support.apple.com/kb/HT4175. Then you should erase all your data repeatedly (atleast 7 times). DoD calls this 7-pass wipe. This encryption, decryption and deletion should give you a bit of a protection. To be extra sure, I would also delete the keyboard cache:
- General > Reset.
- Reset Keyboard Dictionary.
All the keystrokes entered on an iPhone are potentially cached for up to 12 months under the /var/mobile/Library/Keyboard/dynamic-text.dat file for auto-correction, and other purposes.
If you are really the paranoid types, you could buy the iErase app (http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300428114&mt=8) and post all the deletion run it.