Monotouch by example: Working with the keychain

One of the things you will be doing a lot in your apps is storing and retrieving passwords. Most apps today use some form of cloud service, that requires usernames and passwords at one moment or another. Of course you can store usernames and passwords inside the storage folder of the app, but that's easy to hack by people that really want to break into the app.<!--more-->

The best way to store passwords on your iPhone or iPad is to use the keychain. In this post I will show you some of the basics needed to get the keychain to work in your app and what you need to look out for when working with this API. <h2>Basic principles of the keychain</h2> The idea behind the keychain in iOS is to provide developers to securely store certificates, passwords and other data that needs to be encrypted before storage. The same API is used on Mac OS X, with a difference. You can manage your certificates, passwords, etc on there. On iOS you cannot manage the stored data, unless you are a developer and manage the data through the provided API.