secsrv_plat/devenccommonutils_api/inc/DevEncKeyUtils.h
changeset 0 164170e6151a
child 11 510c10de8083
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2007 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 "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:  Provides functions for creating and setting encryption keys.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef DEVENCKEYUTILS_H_
       
    20 #define DEVENCKEYUTILS_H_
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <e32des16.h>
       
    24 #include <e32des8.h>
       
    25 
       
    26 class CFileStore;
       
    27 class CPBEncryptionData;
       
    28 class CPBEncryptElement;
       
    29 class CPBEncryptSet;
       
    30 class RFs;
       
    31 class CDevEncEngineBase;
       
    32 
       
    33 
       
    34 // CLASS DECLARATION
       
    35 /**
       
    36 * Provides functions for creating and setting encryption keys.
       
    37 */
       
    38 class CDevEncKeyUtils: public CBase
       
    39     {
       
    40     public:
       
    41         /**
       
    42         * C++ constructor.
       
    43         */
       
    44         IMPORT_C CDevEncKeyUtils();
       
    45 
       
    46         /**
       
    47         * Destructor.
       
    48         */
       
    49         virtual ~CDevEncKeyUtils();
       
    50 
       
    51         // To connect the engine 
       
    52         IMPORT_C TInt CDevEncKeyUtils::Connect();
       
    53 
       
    54         // To close the connection with the engine
       
    55         IMPORT_C void CDevEncKeyUtils::Close();
       
    56 
       
    57         /**
       
    58         * Creates a PKCS#5 key and takes it into use by loading it
       
    59         * into the security driver. Asynchronous function.
       
    60         * @param aStatus Contains system-wide error code on completion
       
    61         * @param aResult On successful completion, contains PKCS#5
       
    62         *   encrypted key (externalized encryption data and ciphertext)
       
    63         * @param aPassword The user password to use for the key
       
    64         * @param aLength The desired length of the key
       
    65         */
       
    66         IMPORT_C void CreateSetKey( TRequestStatus& aStatus,
       
    67                                     HBufC8*& aResult,
       
    68                                     const TDesC8& aPassword,
       
    69                                     const TInt aLength ) const;
       
    70 
       
    71         /**
       
    72         * Creates a PKCS#5 key and takes it into use by loading it
       
    73         * into the security driver. Asynchronous function. A random password
       
    74         * is generated and the resulting key is ignored. After completion,
       
    75         * the key exists only in the security driver and cannot be retrieved.
       
    76         * @param aStatus Contains system-wide error code on completion
       
    77         * @param aLength The desired length of the key
       
    78         */
       
    79         IMPORT_C void CreateSetKey( TRequestStatus& aStatus,
       
    80                                     const TInt aLength ) const;
       
    81 
       
    82         /**
       
    83         * Sets the specified PKCS#5 key in the security driver.
       
    84         * Asynchronous function.
       
    85         * @param aStatus Contains system-wide error code on completion
       
    86         * @param aPkcs5Key The encrypted PKCS#5 key data (externalized
       
    87         *   encryption data and ciphertext)
       
    88         * @param aPassword The user password to use for the key
       
    89         */
       
    90         IMPORT_C void SetKey( TRequestStatus& aStatus,
       
    91                               const TDesC8& aPkcs5Key,
       
    92                               const TDesC8& aPassword ) const;
       
    93 
       
    94         /**
       
    95         * Resets the key in the security driver. Asynchronous function.
       
    96         * @param aStatus Contains system-wide error code on completion
       
    97         */
       
    98         IMPORT_C void ResetKey( TRequestStatus& aStatus ) const;
       
    99         
       
   100     private:
       
   101     // Functions
       
   102         void DoCreateSetKeyL( const TDesC8& aPassword,
       
   103                               TInt aLength ) const;
       
   104         void DoCreateSetKeyL( HBufC8*& aResult,
       
   105                               const TDesC8& aPassword,
       
   106                               const TInt aLength ) const;
       
   107         void DoSetKeyL( const TDesC8& aPkcs5Key,
       
   108                         const TDesC8& aPassword ) const;
       
   109         
       
   110         void Pkcs5RemovePadding( TPtr8& aInput ) const;
       
   111 
       
   112         void GetNewFileStoreL( RFs& aFs,
       
   113                                TDes& aFileName,
       
   114                                CFileStore*& aStore ) const;
       
   115         
       
   116         void SaveKeyL( CFileStore* aStore,
       
   117                        const CPBEncryptElement* aSet,
       
   118                        const TDesC8& aCiphertext ) const;        
       
   119         
       
   120         void LoadKeyLC( RFs& aFs,
       
   121                         const TFileName& aFileName,
       
   122                         CPBEncryptionData*& aData,
       
   123                         HBufC8*& aCiphertext ) const;
       
   124 
       
   125         void InternalizeKeyL( CPBEncryptElement*& aElement,
       
   126                               const TDesC8& aPassword,
       
   127                               HBufC8*& aCiphertext,
       
   128                               const TDesC8& aSource ) const;
       
   129 
       
   130         void ExternalizeKeyL( const CPBEncryptElement* aElement,
       
   131                               const TDesC8& aCiphertext,
       
   132                               //HBufC8*& aResult ) const;
       
   133                               TDes8& aResult ) const;
       
   134 
       
   135         TBool ProcessHasCapability( TCapability aCapability ) const;
       
   136 
       
   137         void LoadDevEncEngineL();
       
   138 
       
   139         void UnloadDevEncEngine();
       
   140 
       
   141     // Data
       
   142     private:
       
   143        CDevEncEngineBase* iDevEncEngine;
       
   144        RLibrary iLibrary;
       
   145        TBool iConnect;
       
   146     };
       
   147 
       
   148 #endif /*DEVENCKEYUTILS_H_*/
       
   149 
       
   150 // End of file