Symbian3/PDK/Source/GUID-384A25D6-EC89-576E-857F-D8D26292FED9.dita
changeset 1 25a17d01db0c
child 3 46218c8b8afa
equal deleted inserted replaced
0:89d6a7a84779 1:25a17d01db0c
       
     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-384A25D6-EC89-576E-857F-D8D26292FED9" xml:lang="en"><title> Importing
       
    13 Keys</title><shortdesc>This section describes how to import a key from a file using the
       
    14 keystore. </shortdesc><prolog><metadata><keywords/></metadata></prolog><taskbody>
       
    15 <context><p>An externally generated key can be stored in the keystore using
       
    16 the import functionality. Use the <xref href="GUID-818689D6-EB99-382E-A435-D9C6C5D464DE.dita#GUID-818689D6-EB99-382E-A435-D9C6C5D464DE/GUID-9A2E3ABC-4992-31F1-B03E-090DB3C6DC66"><apiname>CUnifiedKeyStore::ImportKey()</apiname></xref> function
       
    17 to import a key into the keystore. </p><p> The following steps explain the
       
    18 process of importing keys:</p> </context>
       
    19 <steps id="GUID-7AD9B618-A5E5-5C32-82D4-1B8E18B13C2C">
       
    20 <step id="GUID-0349CB41-E21A-5BED-BB0C-5A9AFE3AF7CA"><cmd/>
       
    21 <info>Create a file system session using an <xref href="GUID-E263C747-946F-35AA-9F1D-41833BD350FC.dita"><apiname>RFs</apiname></xref> object. </info>
       
    22 </step>
       
    23 <step id="GUID-72A8537C-75A3-51B4-ACD2-0647A69D5528"><cmd/>
       
    24 <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> function. </info>
       
    25 </step>
       
    26 <step id="GUID-AF402EF4-C1A5-5124-9C21-4A45B81F1D0C"><cmd/>
       
    27 <info>Initialize the member functions and keystore using the asynchronous
       
    28 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>
       
    29 </step>
       
    30 <step id="GUID-03708DBC-2367-55CE-B492-1E3CE0F42EA6"><cmd/>
       
    31 <info>Open the file in read-only mode using the <xref href="GUID-BE0804F6-4375-3C8A-8C83-968F510466E0.dita"><apiname>RFile</apiname></xref> object. </info>
       
    32 </step>
       
    33 <step id="GUID-00E736F5-E3AA-5537-92EC-8D287790516E"><cmd/>
       
    34 <info>Import the key using <xref href="GUID-818689D6-EB99-382E-A435-D9C6C5D464DE.dita#GUID-818689D6-EB99-382E-A435-D9C6C5D464DE/GUID-9A2E3ABC-4992-31F1-B03E-090DB3C6DC66"><apiname>CUnifiedKeyStore::ImportKey()</apiname></xref>. </info>
       
    35 </step>
       
    36 </steps>
       
    37 <result><p>The required key is imported into the selected keystore. </p> </result>
       
    38 <example><title>Example</title> <p>The following code snippet shows how to
       
    39 create a file system session object, initialize keystore and member functions,
       
    40 and import a key. </p> <codeblock id="GUID-3FB35264-562C-5FD8-B3B6-1770BF5CA28D" xml:space="preserve">
       
    41 //Create a file system session object
       
    42 RFs iFs;
       
    43 CleanupClosePushL(&amp;iFs);
       
    44 
       
    45 
       
    46 
       
    47 //Initialise the keystore and member functions
       
    48 CUnifiedKeyStore* keyStore = CUnifiedKeyStore::NewL(iFs);
       
    49 keyStore-&gt;Initialize(iStatus); //iStatus is a TRequestStatus object
       
    50 
       
    51 
       
    52 ...
       
    53 
       
    54 
       
    55 HBufC8* keyData = NULL;
       
    56 CleanupStack::PushL(keyData);
       
    57 
       
    58 
       
    59 
       
    60 // Specify the path of the file containing the key details
       
    61 TDriveUnit sysDrive (RFs::GetSystemDrive());
       
    62 TFileName keyDataFile (sysDrive.Name());
       
    63 keyDataFile.Append(_LIT("&lt;path where key is located; relative to the system drive in this case.&gt;"));
       
    64 
       
    65 
       
    66 //Specify the filename
       
    67 TFileName buf;
       
    68 buf.FillZ();
       
    69 buf.Copy(aDes); //Filename
       
    70 keyDataFile.Append(buf); 
       
    71 
       
    72 
       
    73 //Open the file in read-only mode
       
    74 RFile file;
       
    75 User::LeaveIfError(file.Open(iFs, keyDataFile, EFileRead));
       
    76 CleanupClosePushL(file);
       
    77 
       
    78 TInt fileSize = 0;
       
    79 User::LeaveIfError(file.Size(fileSize));
       
    80 HBufC8* iKeyData;
       
    81 
       
    82 if (fileSize &gt; 0)
       
    83     {
       
    84      iKeyData = HBufC8::NewMaxLC(fileSize);    
       
    85      TPtr8 data(iKeyData-&gt;Des());
       
    86      data.FillZ();
       
    87      User::LeaveIfError(file.Read(data, fileSize));
       
    88     }
       
    89 
       
    90 
       
    91 
       
    92 //Import the key into the keystore
       
    93 keyStore-&gt;ImportKey(0, iKeyData-&gt;Des(), usage, KLabel, accessType,
       
    94                 TTime(0), keyInfo, iStatus);
       
    95 
       
    96 
       
    97 //Clean up
       
    98 CleanupStack::Pop(keyData);
       
    99 CleanupStack::PopAndDestroy(); // file
       
   100 CleanupStack::PopAndDestroy(); // iFs</codeblock> </example>
       
   101 </taskbody><related-links>
       
   102 <link href="GUID-C4389D60-2A8D-532D-9D92-E57B0CCD14CF.dita"><linktext>Unified Keystore</linktext>
       
   103 </link>
       
   104 </related-links></task>