|
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-93069514-BC40-5E53-B126-F5C5C43C3D83" xml:lang="en"><title>Exporting |
|
13 a Private Key</title><shortdesc>This section explains the steps to export a private key from the |
|
14 keystore. Private keys can be exported in plain text and encrypted formats. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody> |
|
15 <context><p>The following steps explain the process of exporting a private |
|
16 key: </p></context> |
|
17 <steps id="GUID-57C9001B-6CC1-5178-8B12-26E62649DD30"> |
|
18 <step id="GUID-D7C51FBC-5075-5CBB-AB88-760C522B1371"><cmd/> |
|
19 <info>Create a file system session using an <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita"><apiname>RFs</apiname></xref> object. </info> |
|
20 </step> |
|
21 <step id="GUID-1B781B79-7AC3-5075-A2CB-8852076D5CEA"><cmd/> |
|
22 <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> |
|
23 </step> |
|
24 <step id="GUID-801F826D-B469-5D19-90FF-D78A4C69A302"><cmd/> |
|
25 <info>Initialise the member functions and keystore using the asynchronous |
|
26 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> |
|
27 </step> |
|
28 <step id="GUID-C7934758-ACC0-5343-8A7E-E4D5BFDB53C9"><cmd/> |
|
29 <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 |
|
30 the keys of the keystore. Retrieve the handle of the private key to be exported. </info> |
|
31 </step> |
|
32 <step id="GUID-4B27945E-3202-5044-9B38-A30768721F1C"><cmd/> |
|
33 <info>Invoke the <xref href="GUID-818689D6-EB99-382E-A435-D9C6C5D464DE.dita#GUID-818689D6-EB99-382E-A435-D9C6C5D464DE/GUID-C94CA3E9-F2D9-32B4-B691-29FF58293264"><apiname>CUnifiedKeyStore::ExportKey()</apiname></xref> function |
|
34 for exporting the private key in plain text format or the <xref href="GUID-818689D6-EB99-382E-A435-D9C6C5D464DE.dita#GUID-818689D6-EB99-382E-A435-D9C6C5D464DE/GUID-74223F7E-C4D2-3208-88FE-03D14860A5A6"><apiname>CUnifiedKeyStore::ExportEncryptedKey()</apiname></xref> function |
|
35 for exporting in encrypted format. </info> |
|
36 </step> |
|
37 </steps> |
|
38 <result><p>A private key is exported in plain text or encrypted format. </p> </result> |
|
39 <example id="GUID-0C2E82D5-5297-5A9C-A258-26B2DA29BC9A"><title>Example</title> <p>The |
|
40 following code snippet shows how to set a file system session object, list |
|
41 the keys in the keystore and then export the selected private key in plain |
|
42 text format. </p> <codeblock id="GUID-E6FECC50-782D-5B03-B680-A58E7A1F3651" xml:space="preserve"> |
|
43 |
|
44 //Create a file system session object |
|
45 RFs iFs; |
|
46 CleanupClosePushL(&iFs); |
|
47 |
|
48 |
|
49 //Initialise the keystore and member functions |
|
50 CUnifiedKeyStore* keyStore = CUnifiedKeyStore::NewL(iFs); |
|
51 keyStore->Initialize(iStatus); //iStatus is a TRequestStatus object |
|
52 |
|
53 |
|
54 //List the keys of the keystore |
|
55 RPointerArray<CCTKeyInfo> iKeys; //This variable will contain the result after the completion of the export operation |
|
56 TCTKeyAttributeFilter filter.iUsage = EPKCS15UsageAll; |
|
57 keyStore->List(iKeys, filter, iStatus); |
|
58 |
|
59 ... |
|
60 |
|
61 |
|
62 //Retrieve the handle of the private key to be exported |
|
63 _LIT(KLabel,”keylabel”); |
|
64 TInt keyIndex; |
|
65 |
|
66 //Select the key |
|
67 for (TInt j = 0; j < iKeys.Count(); j++) |
|
68 { |
|
69 if (iKeys[j]->Label() == KLabel) |
|
70 { |
|
71 keyIndex = j; |
|
72 break; |
|
73 } |
|
74 } |
|
75 |
|
76 ... |
|
77 |
|
78 |
|
79 //Export the key |
|
80 HBufC8* iKeyData = NULL; |
|
81 TCTTokenObjectHandle aHandle = iKeys[keyIndex]->Handle(); |
|
82 keyStore->ExportKey(aHandle, iKeyData, iStatus); |
|
83 |
|
84 |
|
85 //Clean up |
|
86 CleanupStack::PopAndDestroy(); // iFs</codeblock> </example> |
|
87 </taskbody><related-links> |
|
88 <link href="GUID-F6625E22-BFB2-5367-A1A8-916252999B78.dita"><linktext>Exporting |
|
89 a Public Key</linktext></link> |
|
90 </related-links></task> |