crypto/weakcrypto/inc/pbe.h
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the 
       
    16 * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 /**
       
    24  @file
       
    25  @publishedPartner
       
    26  @released
       
    27 */
       
    28 
       
    29 #ifndef __PBE_H__
       
    30 #define __PBE_H__
       
    31 
       
    32 #include <e32std.h>
       
    33 #include "pbebase.h"
       
    34 
       
    35 class CPBEncryptionData;
       
    36 class CPBEncryptor;
       
    37 class CPBDecryptor;
       
    38 
       
    39 /** 
       
    40  * Password Based Encryption ciphers.
       
    41  *
       
    42  * Note that RC2 has an additional key parameter, the "effective key length".
       
    43  *
       
    44  * Used in the construction of CPBEncryptElement, CPBEncryptSet, CPBEncryptParms,
       
    45  * and CPBEncryptionData objects and in the CPBEncryptParms::Cipher() function.
       
    46  */
       
    47 enum TPBECipher
       
    48 	{
       
    49 	/** AES cipher in CBC mode with a supplied key size of 128 bits. */
       
    50 	ECipherAES_CBC_128,
       
    51 	/** AES cipher in CBC mode with a supplied key size of 192 bits. */
       
    52 	ECipherAES_CBC_192,
       
    53 	/** AES cipher in CBC mode with a supplied key size of 256 bits. */
       
    54 	ECipherAES_CBC_256,
       
    55 	/** DES cipher in CBC mode (with a supplied key size of 56 bits). */
       
    56 	ECipherDES_CBC,
       
    57 	/** Triple-DES cipher in CBC mode. */
       
    58 	ECipher3DES_CBC,
       
    59 	/** 
       
    60 	 * RC2 cipher in CBC mode with a supplied key length of 40 bits.
       
    61 	 * 
       
    62 	 * It has an effective key length of 1024 bits (128 bytes), which is compatible
       
    63 	 * with OpenSSL RC2 encryption.
       
    64 	 */
       
    65 	ECipherRC2_CBC_40, 
       
    66 	/**
       
    67 	 * RC2 cipher in CBC mode with a supplied key length of 128 bits. 
       
    68 	 * 
       
    69 	 * It has an effective key length of 1024 bits (128 bytes), which is compatible
       
    70 	 * with OpenSSL RC2 encryption.
       
    71 	 */
       
    72 	ECipherRC2_CBC_128,
       
    73 	/**
       
    74 	 * RC2 cipher in CBC mode with a supplied key length of 40 bits.
       
    75 	 * 
       
    76 	 * It has an effective key length of 128 bits (16 bytes), which is compatible 
       
    77 	 * with the RC2 encryption used in PKCS#8 encryption keys generated by OpenSSL
       
    78 	 */
       
    79 	ECipherRC2_CBC_40_16,
       
    80 	/**
       
    81 	 * RC2 cipher in CBC mode with a supplied key length of 128 bits. 
       
    82 	 * 
       
    83 	 * It has an effective key length of 128 bits (16 bytes), which is compatible 
       
    84 	 * with the RC2 encryption used in PKCS#8 encryption keys generated by OpenSSL
       
    85 	 */
       
    86 	ECipherRC2_CBC_128_16,
       
    87 	/**
       
    88 	 * ARC4 cipher with a supplied key length of 128 bits. 
       
    89 	 * PKCS#12 PBE encryption algorithm 
       
    90 	 */
       
    91 	ECipherARC4_128,
       
    92 	/**
       
    93 	 * ARC4 cipher with a supplied key length of 40 bits. 
       
    94 	 * PKCS#12 PBE encryption algorithm 
       
    95 	 */
       
    96     ECipherARC4_40,    
       
    97 	/**
       
    98 	 * 2_KeyTriple-DES cipher in CBC mode. 
       
    99 	 * PKCS#12 PBE encryption algorithm
       
   100 	 */
       
   101     ECipher2Key3DES_CBC,
       
   102 	/** 
       
   103 	 *	RC2 Cipher in CBC mode with a supplied & effective key length of 40 bits. 
       
   104 	 *  PKCS#12 PBE encryption algorithm
       
   105 	 */
       
   106     ECipherRC2_CBC_40_5,
       
   107     };
       
   108 
       
   109 /** 
       
   110  * Allows the password based encryption and decryption of elements.
       
   111  * Contains the encryption key and its associated encryption data.
       
   112  * See the Cryptography api-guide documentation for more information 
       
   113  * and sample code.
       
   114  */
       
   115 class CPBEncryptElement : public CPBEncryptionBase
       
   116 	{
       
   117 public:
       
   118 	/**
       
   119 	 * Creates a new CPBEncryptElement object for encryption of new data.
       
   120 	 *
       
   121 	 * If strong cryptography is present, a 128 bit AES cipher is used; 
       
   122 	 * otherwise, for weak cryptography, a 56 bit DES cipher is used.
       
   123 	 *
       
   124 	 * The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
       
   125 	 * 
       
   126 	 * @param aPassword	The user supplied password
       
   127 	 * @return			The new CPBEncryptElement object
       
   128 	 */
       
   129 	IMPORT_C static CPBEncryptElement* NewL(const TPBPassword& aPassword);
       
   130 
       
   131 	/**
       
   132 	 * Creates a new CPBEncryptElement object for encryption of new data.
       
   133 	 * 
       
   134 	 * If strong cryptography is present, a 128 bit AES cipher is used; 
       
   135 	 * otherwise, for weak cryptography, a 56 bit DES cipher is used.
       
   136 	 *
       
   137 	 * The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
       
   138 	 *
       
   139 	 * A pointer to the returned object is put onto the cleanup stack.
       
   140 	 *
       
   141 	 * @param aPassword	The user supplied password
       
   142 	 * @return			The new CPBEncryptElement object
       
   143 	 */
       
   144 	IMPORT_C static CPBEncryptElement* NewLC(const TPBPassword& aPassword);
       
   145 
       
   146 	/**
       
   147 	 * Creates a new CPBEncryptElement object for encryption of new data.
       
   148 	 *
       
   149 	 * The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
       
   150 	 * 
       
   151 	 * @param aPassword	The user supplied password
       
   152 	 * @param aCipher	The cipher to use
       
   153 	 * @return			The new CPBEncryptElement object
       
   154 	 */
       
   155 	IMPORT_C static CPBEncryptElement* NewL(const TPBPassword& aPassword, 
       
   156 		TPBECipher aCipher);
       
   157 
       
   158 	/**
       
   159 	 * Creates a new CPBEncryptElement object for encryption of new data.
       
   160 	 *
       
   161 	 * The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
       
   162 	 * 
       
   163 	 * A pointer to the returned object is put onto the cleanup stack.
       
   164 	 *
       
   165 	 * @param aPassword	The user supplied password
       
   166 	 * @param aCipher	The cipher to use
       
   167 	 * @return			The new CPBEncryptElement object
       
   168 	 */
       
   169 	IMPORT_C static CPBEncryptElement* NewLC(const TPBPassword& aPassword, 
       
   170 		TPBECipher aCipher);
       
   171 
       
   172 	/**
       
   173 	 * Creates a new CPBEncryptElement object for encryption of new data.
       
   174 	 *
       
   175 	 * The symmetric key is derived from the password using TPKCS5KDF::DeriveKeyL().
       
   176 	 * 
       
   177 	 * @param aPassword	The user supplied password
       
   178 	 * @param aParms	An encryption parameter object comprising the cipher,
       
   179 	 *					salt, IV, and iteration count value. 
       
   180 	 * @return			The new CPBEncryptElement object
       
   181 	 */
       
   182 	IMPORT_C static CPBEncryptElement* NewL(const TPBPassword& aPassword, 
       
   183 		const CPBEncryptParms& aParms);
       
   184 
       
   185 	/**
       
   186 	 * Creates a new CPBEncryptElement object for encryption of new data.
       
   187 	 *
       
   188 	 * The symmetric key is derived from the password using TPKCS5KDF::DeriveKeyL().
       
   189 	 * 
       
   190 	 * A pointer to the returned object is put onto the cleanup stack.
       
   191 	 *
       
   192 	 * @param aPassword	The user supplied password
       
   193 	 * @param aParms	An encryption parameter object comprising the cipher,
       
   194 	 *					salt, IV, and iteration count value. 
       
   195 	 * @return			The new CPBEncryptElement object
       
   196 	 */
       
   197 	IMPORT_C static CPBEncryptElement* NewLC(const TPBPassword& aPassword, 
       
   198 		const CPBEncryptParms& aParms);
       
   199 
       
   200 	/**
       
   201 	 * Creates a new CPBEncryptElement object for decryption of existing data.
       
   202 	 *
       
   203 	 * If the specified password is valid, the function regenerates the encryption key;
       
   204 	 * otherwise, it leaves with KErrBadPassphrase.
       
   205 	 *
       
   206 	 * @param aData				The encryption data object
       
   207 	 * @param aPassword			The user supplied password
       
   208 	 * @return					The new CPBEncryptElement object
       
   209 	 * @leave KErrBadPassphrase	If the specified password is incorrect
       
   210 	 */
       
   211 	IMPORT_C static CPBEncryptElement* NewL(const CPBEncryptionData& aData,
       
   212 		const TPBPassword& aPassword);
       
   213 
       
   214 	/**
       
   215 	 * Creates a new CPBEncryptElement object for decryption of existing data.
       
   216 	 *
       
   217 	 * If the specified password is valid, the function regenerates the encryption key;
       
   218 	 * otherwise, it leaves with KErrBadPassphrase.
       
   219 	 *
       
   220 	 * A pointer to the returned object is put onto the cleanup stack.
       
   221 	 *
       
   222 	 * @param aData				The encryption data object
       
   223 	 * @param aPassword			The user supplied password
       
   224 	 * @return					The new CPBEncryptElement object
       
   225 	 * @leave KErrBadPassphrase	If the specified password is incorrect
       
   226 	 */
       
   227 	IMPORT_C static CPBEncryptElement* NewLC(const CPBEncryptionData& aData,
       
   228 		const TPBPassword& aPassword);
       
   229 
       
   230 	/** 
       
   231 	 * Gets the parameters allowing one to re-create the object with the
       
   232 	 * same state at another point in the future.  
       
   233 	 * 
       
   234 	 * In order to decrypt any information previously encrypted with this object, 
       
   235 	 * you <B><I>must</I></B> store this encryption data along with it. Failure 
       
   236 	 * to do this will result in the permanent loss of the encrypted information.
       
   237 	 * 
       
   238 	 * @return The data allowing one to re-create this object at a later time.					
       
   239 	 */
       
   240 	const CPBEncryptionData& EncryptionData(void) const;
       
   241 
       
   242 	/** 
       
   243 	 * Constructs a CPBEncryptor object allowing the encryption of data.
       
   244 	 * 
       
   245 	 * @return	A pointer to a CPBEncryptor object.
       
   246 	 *			The caller assumes ownership of the returned object.
       
   247 	 */
       
   248 	CPBEncryptor* NewEncryptL(void) const;
       
   249 
       
   250 	/** 
       
   251 	 * Constructs a CPBEncryptor object allowing the encryption of data.
       
   252 	 * 
       
   253 	 * @return	A pointer to a CPBEncryptor object.
       
   254 	 *			The caller assumes ownership of the returned object.
       
   255 	 *			The returned pointer is left on the cleanup stack.
       
   256 	 */
       
   257 	CPBEncryptor* NewEncryptLC(void) const;
       
   258 
       
   259 	/** 
       
   260 	 * Constructs a CPBDecryptor object allowing the decryption of data.
       
   261 	 * 
       
   262 	 * @return	A pointer to a CPBDecryptor object.
       
   263 	 *			The caller assumes ownership of the returned object.
       
   264 	 */
       
   265 	CPBDecryptor* NewDecryptL(void) const;
       
   266 
       
   267 	/** 
       
   268 	 * Constructs a CPBDecryptor object allowing the decryption of data.
       
   269 	 * 
       
   270 	 * @return	A pointer to a CPBDecryptor object.
       
   271 	 *			The caller assumes ownership of the returned object.
       
   272 	 *			The returned pointer is left on the cleanup stack.
       
   273 	 */
       
   274 	CPBDecryptor* NewDecryptLC(void) const;
       
   275 
       
   276 	/** 
       
   277 	 * Gets the maximum output ciphertext length given a specified input plaintext length.  
       
   278 	 * 
       
   279 	 * @param aPlaintextLength	The plaintext length 
       
   280 	 * @return					The maximum ciphertext length given a plaintext length.
       
   281 	 */
       
   282 	TInt MaxCiphertextLength(TInt aPlaintextLength) const;
       
   283 
       
   284 	/** 
       
   285 	 * Gets the maximum output plaintext length given a specified input ciphertext length.
       
   286 	 *
       
   287 	 * @param aCiphertextLength	The ciphertext length
       
   288 	 * @return					The maximum plaintext length given a ciphertext length.
       
   289 	 */
       
   290 	TInt MaxPlaintextLength(TInt aCiphertextLength) const;
       
   291 
       
   292 	/** Destructor */
       
   293 	virtual ~CPBEncryptElement(void);
       
   294 protected:
       
   295 	/** @internalAll */
       
   296 	void ConstructL(const TDesC8& aPassword);
       
   297 	/** @internalAll */
       
   298 	void ConstructL(const TDesC8& aPassword, const TPBECipher aCipher);
       
   299 	/** @internalAll */
       
   300 	void ConstructL(const TDesC8& aPassword, const CPBEncryptParms& aParms);
       
   301 	/** @internalAll */
       
   302 	void ConstructL(const CPBEncryptionData& aData, const TPBPassword& aPassword);
       
   303 	/** @internalAll */
       
   304 	TBool AuthenticateL(const TPBPassword& aPassword);
       
   305 	/** @internalAll */
       
   306 	void MakeEncryptKeyL(TUint aKeySize, const TDesC8& aPassword);
       
   307 	/** @internalAll */
       
   308 	CPBEncryptElement(void);
       
   309 protected:
       
   310 	/** The encryption data */
       
   311 	CPBEncryptionData* iData;
       
   312 	/** The derived encryption key */
       
   313 	HBufC8* iEncryptKey;
       
   314 private:
       
   315 	CPBEncryptElement(const CPBEncryptElement&);
       
   316 	CPBEncryptElement& operator= (const CPBEncryptElement&);
       
   317 	};
       
   318 
       
   319 /** 
       
   320  * Derived class to allow the efficient password based encryption and
       
   321  * decryption of multiple elements.
       
   322  * 
       
   323  * This is useful if one wants random access to an encrypted source consisting 
       
   324  * of multiple independent elements, for example, a database or a store. 
       
   325  * 
       
   326  * Since it is unreasonable to force the decryption of an entire set to allow 
       
   327  * access to just a tiny portion of it, and since it is too costly to derive separate 
       
   328  * keys for each element within the set, a single randomly generated <I>master</I> 
       
   329  * key is used.  This master key is encrypted with the password provided by the 
       
   330  * user of the class. Known plaintext attacks against the ciphertext are prevented 
       
   331  * by using a randomly chosen Initialisation Vector (IV) for each element.  
       
   332  * 
       
   333  * Contains the master encryption key.
       
   334  *
       
   335  * See the Cryptography api-guide documentation for more information and sample code.
       
   336  *
       
   337  * @see CPBEncryptElement
       
   338  * 
       
   339  * @since v8.0
       
   340  */
       
   341 class CPBEncryptSet : public CPBEncryptElement
       
   342 	{
       
   343 public:
       
   344 	/**
       
   345 	 * Creates a new CPBEncryptSet object for encryption of new data 
       
   346 	 * (and generates an encrypted master key).
       
   347 	 *
       
   348 	 * If strong cryptography is present, a 128 bit AES cipher is used; 
       
   349 	 * otherwise, for weak cryptography, a 56 bit DES cipher is used.
       
   350 	 *
       
   351 	 * The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
       
   352 	 *
       
   353 	 * @param aPassword	The users password.
       
   354 	 * @return			A new CPBEncryptSet object
       
   355 	 */
       
   356 	IMPORT_C static CPBEncryptSet* NewL(const TPBPassword& aPassword);
       
   357 
       
   358 	/**
       
   359 	 * Creates a new CPBEncryptSet object for encryption of new data 
       
   360 	 * (and generates an encrypted master key).
       
   361 	 *
       
   362 	 * The returned pointer is put onto the cleanup stack.
       
   363 	 *
       
   364 	 * If strong cryptography is present, a 128 bit AES cipher is used; 
       
   365 	 * otherwise, for weak cryptography, a 56 bit DES cipher is used.
       
   366 	 *
       
   367 	 * The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
       
   368 	 *
       
   369 	 * @param aPassword	The user supplied password
       
   370 	 * @return			The new CPBEncryptSet object
       
   371 	 */
       
   372 	IMPORT_C static CPBEncryptSet* NewLC(const TPBPassword& aPassword);
       
   373 
       
   374 	/**
       
   375 	 * Creates a new CPBEncryptSet object for encryption of new data 
       
   376 	 * (and generates an encrypted master key).
       
   377 	 *
       
   378 	 * The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
       
   379 	 * 
       
   380 	 * @param aPassword	The user supplied password
       
   381 	 * @param aCipher	The cipher to use
       
   382 	 * @return			The new CPBEncryptSet object
       
   383 	 */
       
   384 	IMPORT_C static CPBEncryptSet* NewL(const TPBPassword& aPassword, 
       
   385 		TPBECipher aCipher);
       
   386 
       
   387 	/**
       
   388 	 * Creates a new CPBEncryptSet object for encryption of new data 
       
   389 	 * (and generates an encrypted master key).
       
   390 	 *
       
   391 	 * The returned pointer is put onto the cleanup stack.
       
   392 	 *
       
   393 	 * The symmetric key is derived from the password and a random salt using TPKCS5KDF::DeriveKeyL().
       
   394 	 * 
       
   395 	 * @param aPassword	The user supplied password
       
   396 	 * @param aCipher	The cipher to use
       
   397 	 * @return			The new CPBEncryptSet object
       
   398 	 */
       
   399 	IMPORT_C static CPBEncryptSet* NewLC(const TPBPassword& aPassword, 
       
   400 		TPBECipher aCipher);
       
   401 
       
   402 	/**
       
   403 	 * Creates a new CPBEncryptSet object for encryption of new data 
       
   404 	 * (and generates an encrypted master key).
       
   405 	 *
       
   406 	 * The symmetric key is derived from the password using TPKCS5KDF::DeriveKeyL().
       
   407 	 * 
       
   408 	 * @param aPassword	The user supplied password
       
   409 	 * @param aParms	An encryption parameter object comprising the cipher,
       
   410 	 *					salt, IV, and iteration count value. 
       
   411 	 * @return			The new CPBEncryptSet object
       
   412 	 */
       
   413 	IMPORT_C static CPBEncryptSet* NewL(const TPBPassword& aPassword, 
       
   414 		const CPBEncryptParms& aParms);
       
   415 
       
   416 	/**
       
   417 	 * Creates a new CPBEncryptSet object for encryption of new data 
       
   418 	 * (and generates an encrypted master key).
       
   419 	 *
       
   420 	 * The returned pointer is put onto the cleanup stack.
       
   421 	 *
       
   422 	 * The symmetric key is derived from the password using TPKCS5KDF::DeriveKeyL().
       
   423 	 * 
       
   424 	 * @param aPassword	The user supplied password
       
   425 	 * @param aParms	An encryption parameter object comprising the cipher,
       
   426 	 *					salt, IV, and iteration count value. 
       
   427 	 * @return			The new CPBEncryptSet object
       
   428 	 */
       
   429 	IMPORT_C static CPBEncryptSet* NewLC(const TPBPassword& aPassword, 
       
   430 		const CPBEncryptParms& aParms);
       
   431 
       
   432 	/**
       
   433 	 * Creates a new CPBEncryptSet object for encryption of new data 
       
   434 	 * (and generates an encrypted master key).
       
   435 	 *
       
   436 	 * If the specified password is valid, the function regenerates the encryption key;
       
   437 	 * otherwise, it leaves with KErrBadPassphrase.
       
   438 	 *
       
   439 	 * @param aData					The encryption data object to copy 
       
   440 	 * @param aEncryptedMasterKey	On return, the encrypted master key
       
   441 	 * @param aPassword				The user supplied password
       
   442 	 * @return						The new CPBEncryptSet object
       
   443 	 * @leave KErrBadPassphrase		If the specified password is incorrect
       
   444 	 */
       
   445 	IMPORT_C static CPBEncryptSet* NewL(const CPBEncryptionData& aData,
       
   446 		const TDesC8& aEncryptedMasterKey, const TPBPassword& aPassword);
       
   447 
       
   448 	/**
       
   449 	 * Creates a new CPBEncryptSet object for encryption of new data 
       
   450 	 * (and generates an encrypted master key).
       
   451 	 *
       
   452 	 * The returned pointer is put onto the cleanup stack.
       
   453 	 *
       
   454 	 * If the specified password is valid, the function regenerates the encryption key;
       
   455 	 * otherwise, it leaves with KErrBadPassphrase.
       
   456 	 *
       
   457 	 * @param aData					The encryption data object to copy 
       
   458 	 * @param aEncryptedMasterKey	On return, the encrypted master key
       
   459 	 * @param aPassword				The user supplied password
       
   460 	 * @return						The new CPBEncryptSet object
       
   461 	 * @leave KErrBadPassphrase		If the specified password is incorrect
       
   462 	 */
       
   463 	IMPORT_C static CPBEncryptSet* NewLC(const CPBEncryptionData& aData,
       
   464 		const TDesC8& aEncryptedMasterKey, const TPBPassword& aPassword);
       
   465 	
       
   466 	/** 
       
   467 	 * Gets the encrypted form of the master key.  
       
   468 	 *
       
   469 	 * This must be stored along with the object returned by CPBEncryptElement::EncryptionData() 
       
   470 	 * in order for the object to be reconstructed with the same state at
       
   471      * some time in the future. Failure to do so will result in the permanent
       
   472      * loss of any information encrypted with this object.
       
   473      * 
       
   474      * @return		The encrypted master key.
       
   475      */
       
   476 	IMPORT_C const TDesC8& EncryptedMasterKey(void) const;
       
   477 	
       
   478 	/** 
       
   479 	 * Constructs a CPBEncryptor object based on the state of this object
       
   480 	 * (i.e., the cipher and master key) allowing the encryption of data.
       
   481 	 * 
       
   482 	 * @return	A pointer to a CPBEncryptor object.
       
   483 	 *			The caller assumes ownership of the returned object.
       
   484 	 */
       
   485 	CPBEncryptor* NewEncryptL(void) const;
       
   486 
       
   487 	/** 
       
   488 	 * Constructs a CPBEncryptor object based on the state of this object
       
   489 	 * (i.e., the cipher and master key) allowing the encryption of data.
       
   490 	 * 
       
   491 	 * @return	A pointer to a CPBEncryptor object.
       
   492 	 *			The caller assumes ownership of the returned object.
       
   493 	 *			The returned pointer is left on the cleanup stack.
       
   494 	 */
       
   495 	CPBEncryptor* NewEncryptLC(void) const;
       
   496 
       
   497 	/** 
       
   498 	 * Constructs a CPBDecryptor object based on the state of this object
       
   499 	 * (i.e., the cipher and master key) allowing the decryption of data.
       
   500 	 * 
       
   501 	 * @return	A pointer to a CPBDecryptor object.
       
   502 	 *			The caller assumes ownership of the returned object.
       
   503 	 */
       
   504 	CPBDecryptor* NewDecryptL(void) const;
       
   505 
       
   506 	/** 
       
   507 	 * Constructs a CPBDecryptor object based on the state of this object
       
   508 	 * (i.e., the cipher and master key) allowing the decryption of data.
       
   509 	 * 
       
   510 	 * @return	A pointer to a CPBDecryptor object.
       
   511 	 *			The caller assumes ownership of the returned object.
       
   512 	 *			The returned pointer is left on the cleanup stack.
       
   513 	 */
       
   514 	CPBDecryptor* NewDecryptLC(void) const;
       
   515 
       
   516 	/** 
       
   517      * Re-encrypts the master key with the specified new password.
       
   518      *
       
   519      * @param aNewPassword	The new password
       
   520      */
       
   521 	IMPORT_C void ChangePasswordL(const TPBPassword& aNewPassword);
       
   522 
       
   523 	/** 
       
   524 	 * Gets the maximum output ciphertext length given a specified input plaintext length.  
       
   525 	 * 
       
   526 	 * @param aPlaintextLength	The plaintext length 
       
   527 	 * @return					The maximum ciphertext length given a plaintext length.
       
   528 	 */
       
   529 	TInt MaxCiphertextLength(TInt aPlaintextLength) const;
       
   530 
       
   531 	/** 
       
   532 	 * Gets the maximum output plaintext length given a specified input ciphertext length.
       
   533 	 *
       
   534 	 * @param aCiphertextLength	The ciphertext length
       
   535 	 * @return					The maximum plaintext length given a ciphertext length.
       
   536 	 */
       
   537 	TInt MaxPlaintextLength(TInt aCiphertextLength) const;
       
   538 	
       
   539 	/** Destructor */
       
   540 	virtual ~CPBEncryptSet(void);
       
   541 protected:
       
   542 	/** @internalAll */
       
   543 	void ConstructL(const TDesC8& aPassword);
       
   544 	/** @internalAll */
       
   545 	void ConstructL(const TDesC8& aPassword, TPBECipher aCipher);
       
   546 	/** @internalAll */
       
   547 	void ConstructL(const TDesC8& aPassword, const CPBEncryptParms& aParms);
       
   548 	/** @internalAll */
       
   549 	void ConstructMasterKeyL(void);
       
   550 	/** @internalAll */
       
   551 	void ConstructL(const CPBEncryptionData& aData, 
       
   552 		const TDesC8& aEncryptedMasterKey, const TPBPassword& aPassword);
       
   553 	/** @internalAll */
       
   554 	void DecryptMasterKeyL(TDes8& aMasterKey) const;
       
   555 	/** @internalAll */
       
   556 	void EncryptMasterKeyL(const TDesC8& aMasterKey);
       
   557 protected:
       
   558 	/** @internalAll */
       
   559 	CPBEncryptSet(void);
       
   560 	/** The derived encrypted master key*/
       
   561 	HBufC8* iEncryptedMasterKey;
       
   562 private:
       
   563 	CPBEncryptSet(const CPBEncryptSet&);
       
   564 	CPBEncryptSet& operator= (const CPBEncryptSet&);
       
   565 	};
       
   566 
       
   567 /** 
       
   568  * Class representing both 8 and 16 bit descriptor passwords.
       
   569  * Internally these are stored as 8 bit passwords.
       
   570  */
       
   571 class TPBPassword
       
   572 	{
       
   573 public:
       
   574 	/** 
       
   575 	 * Sets the password.
       
   576 	 * 
       
   577 	 * Constructs a TPBPassword object with an 8 bit descriptor.
       
   578 	 * 
       
   579 	 * Internally this is represented as an octet byte sequence 
       
   580 	 * (aka 8 bit TPtrC8 descriptor).
       
   581 	 * 
       
   582 	 * @param aPassword	A const reference to an 8 bit descriptor.
       
   583 	 * 					representing the users initial password.
       
   584 	 */
       
   585 	IMPORT_C TPBPassword(const TDesC8& aPassword);
       
   586 	
       
   587 	/** 
       
   588 	 * Sets the password.
       
   589 	 * 
       
   590 	 * Constructs a TPBPassword object with a 16 bit descriptor.
       
   591 	 *
       
   592 	 * Internally this is represented as an octet byte sequence
       
   593 	 * (aka 8 bit TPtrC8 descriptor).
       
   594 	 * 
       
   595 	 * @param aPassword	A const reference to a 16 bit descriptor
       
   596 	 * 					representing the users initial password.
       
   597 	 */
       
   598 	IMPORT_C TPBPassword(const TDesC16& aPassword);
       
   599 	
       
   600 	/**
       
   601 	 * Gets the password.
       
   602 	 * 
       
   603 	 * Gets a const reference to an 8 bit descriptor representing the users
       
   604 	 * initial password (which could have been either 8 or 16 bit).
       
   605 	 * 
       
   606 	 * @return		A const reference to an 8 bit descriptor.
       
   607 	 */
       
   608 	IMPORT_C const TDesC8& Password(void) const;
       
   609 private:
       
   610 	TPtrC8 iPassword;
       
   611 	};
       
   612 
       
   613 #endif