Symbian3/SDK/Source/GUID-9E3ADEB4-C000-525D-B220-2BAFF5DC6B0C.dita
changeset 8 ae94777fff8f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Symbian3/SDK/Source/GUID-9E3ADEB4-C000-525D-B220-2BAFF5DC6B0C.dita	Fri Jun 11 12:39:03 2010 +0100
@@ -0,0 +1,82 @@
+<?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 concept
+  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
+<concept xml:lang="en" id="GUID-9E3ADEB4-C000-525D-B220-2BAFF5DC6B0C"><title>Password Based Encryption (PBE) example support code</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>Below is the supporting code for the <xref href="GUID-3385079E-84F4-534F-B937-BD3A568D71BC.dita">PBE example code</xref>. </p> <section id="GUID-8EC8BE08-9961-487A-83C9-766B61C22BB7"><title/><codeblock id="GUID-E9CCC5E6-FDB6-53A0-B7F3-85CFD57FE290" xml:space="preserve">
+#include "e32std.h"
+#include "f32file.h"
+#include "s32file.h"
+#include "pbe.h"
+#include "pbedata.h"
+            </codeblock> <codeblock id="GUID-A6FDAAD3-8418-59BD-BE62-6F4C31F0F3CF" xml:space="preserve">
+/*
+ * Class to demonstrate the use of the PBE API.
+ */
+class CPBEExample : public CBase
+         {
+public:
+         static CPBEExample* NewLC();
+         virtual ~CPBEExample();
+         
+         void WriteEncryptedDataL(const TDesC8&amp; aInput, const TDesC&amp; aFilename, const TDesC&amp; aPassword);
+         HBufC8* ReadEncryptedDataLC(const TDesC&amp; aFilename, const TDesC&amp; aPassword);
+private:
+         CPBEExample();
+         void ConstructL();
+private:
+         RFs iFs;
+         };
+            </codeblock> <codeblock id="GUID-4F7B60AF-62C3-55B3-B1F9-3084D68A97AB" xml:space="preserve">
+CPBEExample* CPBEExample::NewLC()
+         {
+         CPBEExample* self = new (ELeave) CPBEExample();
+         CleanupStack::PushL(self);
+         self-&gt;ConstructL();
+         return self;
+         }
+
+CPBEExample::CPBEExample()
+         {
+         }
+
+void CPBEExample::ConstructL()
+         {
+         User::LeaveIfError(iFs.Connect());
+         }
+
+CPBEExample::~CPBEExample()
+         {
+         iFs.Close();
+         }
+            </codeblock> <codeblock id="GUID-17DECEE0-FE01-5F1F-9143-02462DE3C418" xml:space="preserve">
+LOCAL_D void RunPBEExampleL()
+         {
+         _LIT(KFilename, "c:\\pbe_example_data.dat");
+         _LIT8(KInputData, "This is the data to be encrypted");
+         _LIT(KPassword, "pa55w0rd");
+
+         CPBEExample* main = CPBEExample::NewLC();
+         main-&gt;WriteEncryptedDataL(KInputData, KFilename, KPassword);
+         HBufC8* outputData = main-&gt;ReadEncryptedDataLC(KFilename, KPassword);
+         ASSERT(*outputData == KInputData);
+         CleanupStack::PopAndDestroy(2, main);
+         }
+            </codeblock> <codeblock id="GUID-589330F6-B593-5722-AD3B-73CA53BEDB76" xml:space="preserve">
+GLDEF_C TInt E32Main() // main function called by E32
+    {
+         __UHEAP_MARK;
+         CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack
+         TRAPD(error, RunPBEExampleL());
+         __ASSERT_ALWAYS(!error,User::Panic(_L("pbe_example_code"),error));
+         delete cleanup; // destroy clean-up stack
+         __UHEAP_MARKEND;
+         return 0;
+    }
+            </codeblock> </section> </conbody></concept>
\ No newline at end of file