diff -r 51a74ef9ed63 -r ae94777fff8f Symbian3/SDK/Source/GUID-267D1E20-002E-53C7-8AE5-E063206C1562.dita --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/SDK/Source/GUID-267D1E20-002E-53C7-8AE5-E063206C1562.dita Fri Jun 11 12:39:03 2010 +0100 @@ -0,0 +1,83 @@ + + + + + +Secure stream encryption example support code

Below is the supporting code for the secure stream example code.

<codeblock id="GUID-02ECEC04-E291-51B3-86DF-2FB28347F5AD" 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-13A09565-981A-56C0-9AC7-B849FFBE7395" xml:space="preserve"> +/* + * Class to demonstrate the use of secure stream encryption APIs. + */ +class CSecureStreamExample : public CBase + { +public: + static CSecureStreamExample* NewLC(); + virtual ~CSecureStreamExample(); + + void WriteEncryptedDataL(const TDesC8& aInput, const TDesC& aFilename, const TDesC& aPassword); + HBufC8* ReadEncryptedDataLC(const TDesC& aFilename, const TDesC& aPassword); +private: + CSecureStreamExample(); + void ConstructL(); +private: + RFs iFs; + }; + </codeblock> <codeblock id="GUID-B23E19C7-F6AD-5CB4-A944-EFEDC45AB623" xml:space="preserve"> +CSecureStreamExample* CSecureStreamExample::NewLC() + { + CSecureStreamExample* self = new (ELeave) CSecureStreamExample(); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +CSecureStreamExample::CSecureStreamExample() + { + } + +void CSecureStreamExample::ConstructL() + { + User::LeaveIfError(iFs.Connect()); + } + +CSecureStreamExample::~CSecureStreamExample() + { + iFs.Close(); + } + </codeblock> <codeblock id="GUID-11B8C0DD-AD05-53BB-BAD2-6F31457A2DD9" 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"); + + CSecureStreamExample* main = CSecureStreamExample::NewLC(); + main->WriteEncryptedDataL(KInputData, KFilename, KPassword); + HBufC8* outputData = main->ReadEncryptedDataLC(KFilename, KPassword); + ASSERT(*outputData == KInputData); + CleanupStack::PopAndDestroy(2, main); + } + </codeblock> <codeblock id="GUID-0B93114C-6801-5053-85C3-181779A6185F" 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