diff -r 43e37759235e -r 51a74ef9ed63 Symbian3/SDK/Source/GUID-F6625E22-BFB2-5367-A1A8-916252999B78.dita --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/SDK/Source/GUID-F6625E22-BFB2-5367-A1A8-916252999B78.dita Wed Mar 31 11:11:55 2010 +0100 @@ -0,0 +1,89 @@ + + + + + +Exporting +a Public Key +

A public key is exported in the Distinguished Encoding Rules (DER)-encoded ASN.1 format.

The +following steps explain the process of exporting a public key:

+ + +Create a file system session using an RFs object. + + +Create an object of type CUnifiedKeyStore using CUnifiedKeyStore::NewL() or CUnifiedKeyStore::NewLC(). + + +Initialize the member functions and keystore using the asynchronous +function CUnifiedKeyStore::Initialize(). + + +Use the CUnifiedKeyStore::List() function to list +the keys in the keystore. Retrieve the handle of the public key to be exported. + + +Use the CUnifiedKeyStore::ExportPublic() function +to export the public key. + + +

A public key is exported to the device memory.

+Example

The following code snippet shows how to +set a file system session object, list the keys in the keystore and then export +the selected public key.

+ +//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 result after the completion of the export operation +TCTKeyAttributeFilter filter.iUsage = EPKCS15UsageAll; +keyStore->List(iKeys, filter, iStatus); + +... + + +//Retrieve the handle of the public key to be exported +_LIT(KLabel,”keylabel”); + + +//Select the key with the label you are looking for +TInt keyIndex; +for (TInt j = 0; j < iKeys.Count(); j++) + { + if (iKeys[j]->Label() == KLabel) + { + keyIndex = j; + break; + } + } + + +... + + +//Export the key +HBufC8* iKeyData = NULL; +TCTTokenObjectHandle aHandle = iKeys[keyIndex]->Handle(); +keyStore->ExportPublic(aHandle, iKeyData, iStatus); + + +//Clean up +CleanupStack::PopAndDestroy(); // iFs
+
+Exporting +a Private Key +
\ No newline at end of file