An application can make use of security features that use Keychain as persistent storage for a database encryption key by using the SUPKeyVault APIs defined by the SUPKeyVault class.
The SUPKeyVault class controls setting a key to the keychain, retrieving a key from the keychain, encrypting/decrypting a key with an application PIN, locking/unlocking a key vault with a PIN, and PIN management. An application explicitly retrieves and saves a database encryption key using the SUPKeyVault APIs, then sets the retrieved encryption key to SUPConnectionProfile.
SUPKeyVault * keyvault = [SUPKeyVault getSUPKeyVault:MESSAGING_VAULT_ID]; // keyVault must be unlocked by the application before the connection to server. if ( [keyVault isLocked] ) { // Get the PIN from user through ENTER PIN dialog // Now unlock the KeyVault with the PIN result = [keyVault unlock: pin]; if ( result == error ) { // Take necessary actions } } NSData *dbKey = [keyVault key]; // start up Sybase messaging client after the keyVault is unlocked. NSInteger result = [SUPMessageClient start]; if (result == kSUPMessageClientSuccess) { ... }
SUPConnectionProfile *cp = [SampleApp_SampleAppDB connectionProfile]; [cp setEncryptionKey:dbKey];
if ( ![keyVault isLocked] ) { [keyVault setKey:dbKey]; }