cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_export.cpp
branchRCL_3
changeset 41 9b5a3a9fddf8
parent 8 35751d3474b7
equal deleted inserted replaced
37:721a5e5fe251 41:9b5a3a9fddf8
    28 #include <asn1dec.h>
    28 #include <asn1dec.h>
    29 #include <x509cert.h>
    29 #include <x509cert.h>
    30 #include <x509keys.h>
    30 #include <x509keys.h>
    31 #include <pbe.h>
    31 #include <pbe.h>
    32 #include <pbedata.h>
    32 #include <pbedata.h>
       
    33 #include <securityerr.h>
    33 
    34 
    34 
    35 
    35 const TInt KKeyStoreEmpty = -1199;
    36 const TInt KKeyStoreEmpty = -1199;
    36 const TInt KDefaultSaltSize = 16;
    37 const TInt KDefaultSaltSize = 16;
    37 const TInt KDefaultIVSize = 8;
    38 const TInt KDefaultIVSize = 8;
   102 		// Create default PBE paramenters
   103 		// Create default PBE paramenters
   103 		CSystemRandom* rand = CSystemRandom::NewLC();
   104 		CSystemRandom* rand = CSystemRandom::NewLC();
   104 		HBufC8* saltc = HBufC8::NewMaxLC(KDefaultSaltSize);           
   105 		HBufC8* saltc = HBufC8::NewMaxLC(KDefaultSaltSize);           
   105 		TPtr8 salt(saltc->Des());
   106 		TPtr8 salt(saltc->Des());
   106 		salt.FillZ(); 
   107 		salt.FillZ(); 
   107 		rand->GenerateBytesL(salt);
   108 		TRAPD(err, rand->GenerateBytesL(salt));
       
   109 		if((err != KErrNone) && (err != KErrNotSecure))
       
   110 			User::Leave(err);
   108 
   111 
   109 		HBufC8* ivc = HBufC8::NewMaxLC(KDESBlockBytes);          
   112 		HBufC8* ivc = HBufC8::NewMaxLC(KDESBlockBytes);          
   110 	
   113 	
   111 		TPtr8 iv(ivc->Des());
   114 		TPtr8 iv(ivc->Des());
   112 		iv.FillZ(); 
   115 		iv.FillZ(); 
   113 		rand->GenerateBytesL(iv);	
   116 		TRAP(err, rand->GenerateBytesL(iv));
       
   117 		if((err != KErrNone) && (err != KErrNotSecure))
       
   118 			User::Leave(err);
   114 
   119 
   115 		ASSERT(!iPbeParams);
   120 		ASSERT(!iPbeParams);
   116 		iPbeParams = CPBEncryptParms::NewL(ECipherDES_CBC, salt, iv, 2048); 
   121 		iPbeParams = CPBEncryptParms::NewL(ECipherDES_CBC, salt, iv, 2048); 
   117         
   122         
   118 		CleanupStack::PopAndDestroy(3, rand);     // rand, saltc, ivc
   123 		CleanupStack::PopAndDestroy(3, rand);     // rand, saltc, ivc