Symbian3/SDK/Source/GUID-A56D550A-BF08-5D9C-A64C-67E8654F449B.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Fri, 13 Aug 2010 16:47:46 +0100
changeset 14 578be2adaf3e
parent 0 89d6a7a84779
permissions -rw-r--r--
Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582

<?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-A56D550A-BF08-5D9C-A64C-67E8654F449B" xml:lang="en"><title>Creating
Keys</title><shortdesc>This section explains how to create a key using the keystore. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody>
<context><p>Before you create a key, you must know which keystore the new
key must be stored in. See <xref href="GUID-1733B4E1-3264-58DF-957B-F5C0AE1E0644.dita">Retrieving
Keystores</xref> for more information. </p><p>The following steps explain
the process of creating a key:</p> </context>
<steps id="GUID-5947641D-B308-5E35-B6E1-1E9561A8495B">
<step id="GUID-75536534-0982-54E0-BF52-0BC3DE8A2200"><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-7648129E-7206-5C6A-BDDC-F3AA0A930B87"><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-6DEAD07A-5AAE-5876-B1EF-3728C8C4EB07"><cmd/>
<info>Initialise 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-EE225F78-78B5-54B8-82A7-CCC8A5DBAF01"><cmd/>
<info>Create a key using <xref href="GUID-818689D6-EB99-382E-A435-D9C6C5D464DE.dita#GUID-818689D6-EB99-382E-A435-D9C6C5D464DE/GUID-F4546E33-BCE9-330A-913A-88A0253EF498"><apiname>CUnifiedKeyStore::CreateKey()</apiname></xref>. </info>
</step>
</steps>
<result><p>A new key is created and stored in the selected keystore. </p> </result>
<example><title>Example</title> <p>The following code snippet shows how to
set a file system session object, initialise keystore and member functions,
and create a key. </p> <codeblock id="GUID-6A28C0E5-2708-5875-976B-F319DDC2148F" 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


//Initialise the arguments to be passed into the CreateKey() function
TKeyUsagePKCS15 usage = EPKCS15UsageSign | EPKCS15UsageSignRecover;
TUint keysize = 512;
_LIT(KLabel,”keylabel”);
CCTKeyInfo::EKeyAlgorithm algorithm = CCTKeyInfo::EDSA;
TInt accessType = CCTKeyInfo::EExtractable;    
TTime startDate, endDate;
startDate.HomeTime(); 
endDate.HomeTime();


// Create a pointer for data returned by CreateKey()
CCTKeyInfo* keyInfo;

//Create the key
keyStore-&gt;CreateKey(0, usage, keysize, KLabel, algorithm,
accessType, startDate, endDate, keyInfo, iStatus);


//Clean up
CleanupStack::PopAndDestroy(); // iFs</codeblock> </example>
</taskbody><related-links>
<link href="GUID-C4389D60-2A8D-532D-9D92-E57B0CCD14CF.dita"><linktext>Unified Keystore</linktext>
</link>
</related-links></task>