Symbian3/PDK/Source/GUID-7D53E323-CF8D-5C4D-ABCD-4D95C7A4A5B5-GENID-1-12-1-26-1-1-11-1-1-6-1-5-1-8-1.dita
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Symbian3/PDK/Source/GUID-7D53E323-CF8D-5C4D-ABCD-4D95C7A4A5B5-GENID-1-12-1-26-1-1-11-1-1-6-1-5-1-8-1.dita Fri Jul 16 17:23:46 2010 +0100
@@ -0,0 +1,111 @@
+<?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-7D53E323-CF8D-5C4D-ABCD-4D95C7A4A5B5-GENID-1-12-1-26-1-1-11-1-1-6-1-5-1-8-1"><title>Secure store encryption example support code</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>Below is the supporting code for the <xref href="GUID-36BCDD1F-3713-5DF0-8D8A-CF093694B636-GENID-1-12-1-26-1-1-9-1-12-1-7-1.dita">secure store example code</xref>. </p> <section id="GUID-5DE9A95D-C755-429A-A3E3-7A8FF06008B9-GENID-1-12-1-26-1-1-11-1-1-6-1-5-1-8-1-2-2"><title/><codeblock id="GUID-36F57493-4F6E-559A-B51B-7261F57AF1B1-GENID-1-12-1-26-1-1-11-1-1-6-1-5-1-8-1-2-2-2" xml:space="preserve">
+#include "e32std.h"
+#include "f32file.h"
+#include "s32file.h"
+#include "pbe.h"
+#include "pbedata.h"
+#include "s32crypt.h"
+ </codeblock> <codeblock id="GUID-EE52D935-4E72-5D4A-809C-BA0FEE19C90F-GENID-1-12-1-26-1-1-11-1-1-6-1-5-1-8-1-2-2-3" xml:space="preserve">
+/*
+ * Class to demonstrate the use of secure store APIs.
+ */
+class CSecureStoreExample : public CBase
+ {
+public:
+ static CSecureStoreExample* NewLC(const TDesC& aFilename);
+ virtual ~CSecureStoreExample();
+
+ void CreateNewStoreL(const TDesC& aPassword);
+ TStreamId WriteEncryptedDataL(const TDesC8& aInput);
+ void OpenExistingStoreL(const TDesC& aPassword);
+ HBufC8* ReadEncryptedDataLC(TStreamId aStreamId);
+ void CloseStore();
+ void ChangePasswordL(const TDesC& aNewPassword);
+private:
+ CSecureStoreExample(const TDesC& aFilename);
+ void ConstructL();
+private:
+ RFs iFs;
+ const TDesC& iFilename;
+ CPermanentFileStore* iFileStore;
+ CPBEncryptSet* iEncryptSet;
+ CSecureStore* iSecureStore;
+ };
+ </codeblock> <codeblock id="GUID-DB3DBE48-DCEC-5CDD-9066-246AD37A5C12-GENID-1-12-1-26-1-1-11-1-1-6-1-5-1-8-1-2-2-4" xml:space="preserve">
+CSecureStoreExample* CSecureStoreExample::NewLC(const TDesC& aFilename)
+ {
+ CSecureStoreExample* self = new (ELeave) CSecureStoreExample(aFilename);
+ CleanupStack::PushL(self);
+ self->ConstructL();
+ return self;
+ }
+
+CSecureStoreExample::CSecureStoreExample(const TDesC& aFilename)
+ : iFilename(aFilename)
+ {
+ }
+
+void CSecureStoreExample::ConstructL()
+ {
+ User::LeaveIfError(iFs.Connect());
+ }
+
+CSecureStoreExample::~CSecureStoreExample()
+ {
+ CloseStore();
+ iFs.Close();
+ }
+ </codeblock> <codeblock id="GUID-4485993E-0561-5688-85FA-3914AECDF12B-GENID-1-12-1-26-1-1-11-1-1-6-1-5-1-8-1-2-2-5" 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");
+ _LIT(KNewPassword, "chang3m3");
+
+ CSecureStoreExample* main = CSecureStoreExample::NewLC(KFilename);
+
+ // Create a secure store and write some data to it
+ main->CreateNewStoreL(KPassword);
+ TStreamId streamId = main->WriteEncryptedDataL(KInputData);
+ main->CloseStore();
+
+ // Open it again, and read the data back out
+ main->OpenExistingStoreL(KPassword);
+ HBufC8* outputData = main->ReadEncryptedDataLC(streamId);
+ ASSERT(*outputData == KInputData);
+ CleanupStack::PopAndDestroy(outputData);
+
+ // Change the password
+ main->ChangePasswordL(KNewPassword);
+
+ // Check we can still read the data
+ outputData = main->ReadEncryptedDataLC(streamId);
+ ASSERT(*outputData == KInputData);
+ main->CloseStore();
+
+ CleanupStack::PopAndDestroy(2, main);
+ }
+ </codeblock> <codeblock id="GUID-7FF91AD3-106A-56EA-9199-0E261B8D044C-GENID-1-12-1-26-1-1-11-1-1-6-1-5-1-8-1-2-2-6" 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