|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE task |
|
11 PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd"> |
|
12 <task id="GUID-F6625E22-BFB2-5367-A1A8-916252999B78" xml:lang="en"><title>Exporting |
|
13 a Public Key</title><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
14 <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 |
|
15 following steps explain the process of exporting a public key: </p></context> |
|
16 <steps id="GUID-7ADC22F6-A109-5DD7-BD18-C44E7A77D32D"> |
|
17 <step id="GUID-D0DA1155-B5E7-52C2-8EF6-98624F434832"><cmd/> |
|
18 <info>Create a file system session using an <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita"><apiname>RFs</apiname></xref> object. </info> |
|
19 </step> |
|
20 <step id="GUID-A058B724-1B9D-5F03-85CC-DE633422DFC1"><cmd/> |
|
21 <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> |
|
22 </step> |
|
23 <step id="GUID-C3070E3E-CC56-5C21-A354-68EAEB214939"><cmd/> |
|
24 <info>Initialize the member functions and keystore using the asynchronous |
|
25 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> |
|
26 </step> |
|
27 <step id="GUID-AEAE3C68-F064-57AE-B2B3-4CE0606966F2"><cmd/> |
|
28 <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 |
|
29 the keys in the keystore. Retrieve the handle of the public key to be exported. </info> |
|
30 </step> |
|
31 <step id="GUID-A0B15734-B41A-5BAD-B839-386B9F36075F"><cmd/> |
|
32 <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 |
|
33 to export the public key. </info> |
|
34 </step> |
|
35 </steps> |
|
36 <result><p>A public key is exported to the device memory. </p> </result> |
|
37 <example><title>Example</title> <p>The following code snippet shows how to |
|
38 set a file system session object, list the keys in the keystore and then export |
|
39 the selected public key. </p> <codeblock id="GUID-2D9D08EE-742C-5E19-850C-CD39BFF12D8E" xml:space="preserve"> |
|
40 |
|
41 //Create a file system session object |
|
42 RFs iFs; |
|
43 CleanupClosePushL(&iFs); |
|
44 |
|
45 |
|
46 //Initialise the keystore and member functions |
|
47 CUnifiedKeyStore* keyStore = CUnifiedKeyStore::NewL(iFs); |
|
48 keyStore->Initialize(iStatus); //iStatus is a TRequestStatus object |
|
49 |
|
50 |
|
51 //List the keys of the keystore |
|
52 RPointerArray<CCTKeyInfo> iKeys; // This variable will contain the result after the completion of the export operation |
|
53 TCTKeyAttributeFilter filter.iUsage = EPKCS15UsageAll; |
|
54 keyStore->List(iKeys, filter, iStatus); |
|
55 |
|
56 ... |
|
57 |
|
58 |
|
59 //Retrieve the handle of the public key to be exported |
|
60 _LIT(KLabel,”keylabel”); |
|
61 |
|
62 |
|
63 //Select the key with the label you are looking for |
|
64 TInt keyIndex; |
|
65 for (TInt j = 0; j < iKeys.Count(); j++) |
|
66 { |
|
67 if (iKeys[j]->Label() == KLabel) |
|
68 { |
|
69 keyIndex = j; |
|
70 break; |
|
71 } |
|
72 } |
|
73 |
|
74 |
|
75 ... |
|
76 |
|
77 |
|
78 //Export the key |
|
79 HBufC8* iKeyData = NULL; |
|
80 TCTTokenObjectHandle aHandle = iKeys[keyIndex]->Handle(); |
|
81 keyStore->ExportPublic(aHandle, iKeyData, iStatus); |
|
82 |
|
83 |
|
84 //Clean up |
|
85 CleanupStack::PopAndDestroy(); // iFs</codeblock> </example> |
|
86 </taskbody><related-links> |
|
87 <link href="GUID-93069514-BC40-5E53-B126-F5C5C43C3D83.dita"><linktext>Exporting |
|
88 a Private Key</linktext></link> |
|
89 </related-links></task> |