Symbian3/SDK/Source/GUID-267D1E20-002E-53C7-8AE5-E063206C1562.dita
changeset 8 ae94777fff8f
equal deleted inserted replaced
7:51a74ef9ed63 8:ae94777fff8f
       
     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 concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept xml:lang="en" id="GUID-267D1E20-002E-53C7-8AE5-E063206C1562"><title>Secure stream encryption example support code</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>Below is the supporting code for the <xref href="GUID-598B6698-3518-50CA-98DE-D85CB255BA2D.dita">secure stream example code</xref>. </p> <section id="GUID-77E39C51-FE08-4EEB-B94A-4ECD8104E1ED"><title/><codeblock id="GUID-02ECEC04-E291-51B3-86DF-2FB28347F5AD" xml:space="preserve">
       
    13 #include "e32std.h"
       
    14 #include "f32file.h"
       
    15 #include "s32file.h"
       
    16 #include "pbe.h"
       
    17 #include "pbedata.h"
       
    18 #include "s32crypt.h"
       
    19             </codeblock> <codeblock id="GUID-13A09565-981A-56C0-9AC7-B849FFBE7395" xml:space="preserve">
       
    20 /*
       
    21  * Class to demonstrate the use of secure stream encryption APIs.
       
    22  */
       
    23 class CSecureStreamExample : public CBase
       
    24          {
       
    25 public:
       
    26          static CSecureStreamExample* NewLC();
       
    27          virtual ~CSecureStreamExample();
       
    28          
       
    29          void WriteEncryptedDataL(const TDesC8&amp; aInput, const TDesC&amp; aFilename, const TDesC&amp; aPassword);
       
    30          HBufC8* ReadEncryptedDataLC(const TDesC&amp; aFilename, const TDesC&amp; aPassword);
       
    31 private:
       
    32          CSecureStreamExample();
       
    33          void ConstructL();
       
    34 private:
       
    35          RFs iFs;
       
    36          };
       
    37             </codeblock> <codeblock id="GUID-B23E19C7-F6AD-5CB4-A944-EFEDC45AB623" xml:space="preserve">
       
    38 CSecureStreamExample* CSecureStreamExample::NewLC()
       
    39          {
       
    40          CSecureStreamExample* self = new (ELeave) CSecureStreamExample();
       
    41          CleanupStack::PushL(self);
       
    42          self-&gt;ConstructL();
       
    43          return self;
       
    44          }
       
    45 
       
    46 CSecureStreamExample::CSecureStreamExample()
       
    47          {
       
    48          }
       
    49 
       
    50 void CSecureStreamExample::ConstructL()
       
    51          {
       
    52          User::LeaveIfError(iFs.Connect());
       
    53          }
       
    54 
       
    55 CSecureStreamExample::~CSecureStreamExample()
       
    56          {
       
    57          iFs.Close();
       
    58          }
       
    59             </codeblock> <codeblock id="GUID-11B8C0DD-AD05-53BB-BAD2-6F31457A2DD9" xml:space="preserve">
       
    60 LOCAL_D void RunPBEExampleL()
       
    61          {
       
    62          _LIT(KFilename, "c:\\pbe_example_data.dat");
       
    63          _LIT8(KInputData, "This is the data to be encrypted.");
       
    64          _LIT(KPassword, "pa55w0rd");
       
    65 
       
    66          CSecureStreamExample* main = CSecureStreamExample::NewLC();
       
    67          main-&gt;WriteEncryptedDataL(KInputData, KFilename, KPassword);
       
    68          HBufC8* outputData = main-&gt;ReadEncryptedDataLC(KFilename, KPassword);
       
    69          ASSERT(*outputData == KInputData);
       
    70          CleanupStack::PopAndDestroy(2, main);
       
    71          }
       
    72             </codeblock> <codeblock id="GUID-0B93114C-6801-5053-85C3-181779A6185F" xml:space="preserve">
       
    73 GLDEF_C TInt E32Main() // main function called by E32
       
    74     {
       
    75          __UHEAP_MARK;
       
    76          CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack
       
    77          TRAPD(error, RunPBEExampleL());
       
    78          __ASSERT_ALWAYS(!error,User::Panic(_L("pbe_example_code"),error));
       
    79          delete cleanup; // destroy clean-up stack
       
    80          __UHEAP_MARKEND;
       
    81          return 0;
       
    82     }
       
    83         </codeblock> </section> </conbody></concept>