|
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-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"> |
|
13 #include "e32std.h" |
|
14 #include "f32file.h" |
|
15 #include "s32file.h" |
|
16 #include "pbe.h" |
|
17 #include "pbedata.h" |
|
18 </codeblock> <codeblock id="GUID-A6FDAAD3-8418-59BD-BE62-6F4C31F0F3CF" xml:space="preserve"> |
|
19 /* |
|
20 * Class to demonstrate the use of the PBE API. |
|
21 */ |
|
22 class CPBEExample : public CBase |
|
23 { |
|
24 public: |
|
25 static CPBEExample* NewLC(); |
|
26 virtual ~CPBEExample(); |
|
27 |
|
28 void WriteEncryptedDataL(const TDesC8& aInput, const TDesC& aFilename, const TDesC& aPassword); |
|
29 HBufC8* ReadEncryptedDataLC(const TDesC& aFilename, const TDesC& aPassword); |
|
30 private: |
|
31 CPBEExample(); |
|
32 void ConstructL(); |
|
33 private: |
|
34 RFs iFs; |
|
35 }; |
|
36 </codeblock> <codeblock id="GUID-4F7B60AF-62C3-55B3-B1F9-3084D68A97AB" xml:space="preserve"> |
|
37 CPBEExample* CPBEExample::NewLC() |
|
38 { |
|
39 CPBEExample* self = new (ELeave) CPBEExample(); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CPBEExample::CPBEExample() |
|
46 { |
|
47 } |
|
48 |
|
49 void CPBEExample::ConstructL() |
|
50 { |
|
51 User::LeaveIfError(iFs.Connect()); |
|
52 } |
|
53 |
|
54 CPBEExample::~CPBEExample() |
|
55 { |
|
56 iFs.Close(); |
|
57 } |
|
58 </codeblock> <codeblock id="GUID-17DECEE0-FE01-5F1F-9143-02462DE3C418" xml:space="preserve"> |
|
59 LOCAL_D void RunPBEExampleL() |
|
60 { |
|
61 _LIT(KFilename, "c:\\pbe_example_data.dat"); |
|
62 _LIT8(KInputData, "This is the data to be encrypted"); |
|
63 _LIT(KPassword, "pa55w0rd"); |
|
64 |
|
65 CPBEExample* main = CPBEExample::NewLC(); |
|
66 main->WriteEncryptedDataL(KInputData, KFilename, KPassword); |
|
67 HBufC8* outputData = main->ReadEncryptedDataLC(KFilename, KPassword); |
|
68 ASSERT(*outputData == KInputData); |
|
69 CleanupStack::PopAndDestroy(2, main); |
|
70 } |
|
71 </codeblock> <codeblock id="GUID-589330F6-B593-5722-AD3B-73CA53BEDB76" xml:space="preserve"> |
|
72 GLDEF_C TInt E32Main() // main function called by E32 |
|
73 { |
|
74 __UHEAP_MARK; |
|
75 CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack |
|
76 TRAPD(error, RunPBEExampleL()); |
|
77 __ASSERT_ALWAYS(!error,User::Panic(_L("pbe_example_code"),error)); |
|
78 delete cleanup; // destroy clean-up stack |
|
79 __UHEAP_MARKEND; |
|
80 return 0; |
|
81 } |
|
82 </codeblock> </section> </conbody></concept> |