Deleting Keys

This section provides information on deleting keys.

The unified keystore allows the deletion of any key. The following steps explain the process of deleting a key:


  1. Create a file system session using an RFs object.

  2. Create an object of type CUnifiedKeyStore using CUnifiedKeyStore::NewL() or CUnifiedKeyStore::NewLC().

  3. Initialise the member functions and keystore using the asynchronous function CUnifiedKeyStore::Initialize().

  4. Use the CUnifiedKeyStore::List() function to list the keys of the keystore. Retrieve the handle of the key to be deleted.
  5. Use the CUnifiedKeyStore::DeleteKey() function to delete the key.

The selected key is deleted from the keystore.

Example

The following code snippet shows how to initialise the unified keystore, list the keys in a keystore, select a particular key and delete it.

//Create a file system session object
RFs iFs;
CleanupClosePushL(&iFs);



//Initialise the keystore and member functions
CUnifiedKeyStore* keyStore = CUnifiedKeyStore::NewL(iFs);
keyStore->Initialize(iStatus); //iStatus is a TRequestStatus object


//List the keys of the keystore
RPointerArray<CCTKeyInfo> iKeys; // This variable will contain the key for deletion
TCTKeyAttributeFilter  filter.iUsage = EPKCS15UsageAll;
keyStore->List(iKeys, filter, iStatus);


...



//Retrieve the handle of the key to be deleted
_LIT(KLabel,”keylabel”);



//Select the key with the label you are looking for
for (TInt j = 0; j < iKeys.Count(); j++)
    {
    if (Keys[j]->Label() == KLabel) 
        {
         keyIndex = j;
         break;
        }
    }


...



//Delete the selected key
keyStore->DeleteKey(*iKeys[keyIndex], iStatus);


//Clean up
CleanupStack::PopAndDestroy(); // iFs

Related concepts