Symbian3/PDK/Source/GUID-F6625E22-BFB2-5367-A1A8-916252999B78.dita
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Thu, 11 Mar 2010 18:02:22 +0000
changeset 3 46218c8b8afa
parent 1 25a17d01db0c
child 5 f345bda72bc4
permissions -rw-r--r--
week 10 bug fix submission (SF PDK version): Bug 1892, Bug 1897, Bug 1319. Also 3 or 4 documents were found to contain code blocks with SFL, which has been fixed. Partial fix for broken links, links to Forum Nokia, and the 'Symbian platform' terminology issues.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE task
  PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
<task id="GUID-F6625E22-BFB2-5367-A1A8-916252999B78" xml:lang="en"><title>Exporting
a Public Key</title><prolog><metadata><keywords/></metadata></prolog><taskbody>
<context><p>A public key is exported in the Distinguished Encoding Rules (DER)-encoded <xref href="http://tools.ietf.org/html/rfc4792" scope="external">ASN.1</xref> format.</p><p> The
following steps explain the process of exporting a public key: </p></context>
<steps id="GUID-7ADC22F6-A109-5DD7-BD18-C44E7A77D32D">
<step id="GUID-D0DA1155-B5E7-52C2-8EF6-98624F434832"><cmd/>
<info>Create a file system session using an <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita"><apiname>RFs</apiname></xref> object. </info>
</step>
<step id="GUID-A058B724-1B9D-5F03-85CC-DE633422DFC1"><cmd/>
<info>Create an object of type CUnifiedKeyStore using <xref href="GUID-818689D6-EB99-382E-A435-D9C6C5D464DE.dita#GUID-818689D6-EB99-382E-A435-D9C6C5D464DE/GUID-C7A96153-4179-3B3F-878D-1EAA64A98D39"><apiname>CUnifiedKeyStore::NewL()</apiname></xref> or <xref href="GUID-818689D6-EB99-382E-A435-D9C6C5D464DE.dita#GUID-818689D6-EB99-382E-A435-D9C6C5D464DE/GUID-217FBB3B-CEF5-36F2-A612-EDDA0982053C"><apiname>CUnifiedKeyStore::NewLC()</apiname></xref>. </info>
</step>
<step id="GUID-C3070E3E-CC56-5C21-A354-68EAEB214939"><cmd/>
<info>Initialize the member functions and keystore using the asynchronous
function <xref href="GUID-818689D6-EB99-382E-A435-D9C6C5D464DE.dita#GUID-818689D6-EB99-382E-A435-D9C6C5D464DE/GUID-6C5D732C-1FD1-3EF0-AC90-87690F891B8D"><apiname>CUnifiedKeyStore::Initialize()</apiname></xref>. </info>
</step>
<step id="GUID-AEAE3C68-F064-57AE-B2B3-4CE0606966F2"><cmd/>
<info>Use the <xref href="GUID-818689D6-EB99-382E-A435-D9C6C5D464DE.dita#GUID-818689D6-EB99-382E-A435-D9C6C5D464DE/GUID-8B22E1BC-D779-32DC-9C0A-CA37E4C0A81B"><apiname>CUnifiedKeyStore::List()</apiname></xref> function to list
the keys in the keystore. Retrieve the handle of the public key to be exported. </info>
</step>
<step id="GUID-A0B15734-B41A-5BAD-B839-386B9F36075F"><cmd/>
<info>Use the <xref href="GUID-818689D6-EB99-382E-A435-D9C6C5D464DE.dita#GUID-818689D6-EB99-382E-A435-D9C6C5D464DE/GUID-8C87B9FF-5A81-3EAA-BEC7-65F12855BED7"><apiname>CUnifiedKeyStore::ExportPublic()</apiname></xref> function
to export the public key. </info>
</step>
</steps>
<result><p>A public key is exported to the device memory. </p> </result>
<example><title>Example</title> <p>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. </p> <codeblock id="GUID-2D9D08EE-742C-5E19-850C-CD39BFF12D8E" xml:space="preserve">

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


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


//List the keys of the keystore
RPointerArray&lt;CCTKeyInfo&gt; iKeys; // This variable will contain the result after the completion of the export operation
TCTKeyAttributeFilter  filter.iUsage = EPKCS15UsageAll;
keyStore-&gt;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 &lt; iKeys.Count(); j++)
    {
    if (iKeys[j]-&gt;Label() == KLabel) 
        {
         keyIndex = j;
         break;
        }
    }


...


//Export the key 
HBufC8* iKeyData = NULL;
TCTTokenObjectHandle aHandle = iKeys[keyIndex]-&gt;Handle();
keyStore-&gt;ExportPublic(aHandle, iKeyData, iStatus);


//Clean up
CleanupStack::PopAndDestroy(); // iFs</codeblock> </example>
</taskbody><related-links>
<link href="GUID-93069514-BC40-5E53-B126-F5C5C43C3D83.dita"><linktext>Exporting
a Private Key</linktext></link>
</related-links></task>