websrv_pub/web_service_connection_api/inc/sencryptoutils.h
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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: Crypto graphy utils api declaration
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef C_SEN_CRYPTO_UTILS_H
       
    19 #define C_SEN_CRYPTO_UTILS_H
       
    20 
       
    21 #include <hash.h>
       
    22 
       
    23 
       
    24 /**
       
    25  * Set of static convenience methods to help in cryptography
       
    26  */
       
    27 class SenCryptoUtils
       
    28     {
       
    29     public:
       
    30         /**
       
    31         * Algorithm taken from of TLS specification RFC 2246 - 5.HMAC and the pseudorandom function  
       
    32         *           
       
    33         *           P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
       
    34         *                              HMAC_hash(secret, A(2) + seed) +
       
    35         *                              HMAC_hash(secret, A(3) + seed) + ...
       
    36         *
       
    37         *               Where + indicates concatenation.
       
    38         *
       
    39         *               A() is defined as:
       
    40         *                   A(0) = seed
       
    41         *                   A(i) = HMAC_hash(secret, A(i-1))
       
    42         *
       
    43         *       P_hash can be iterated as many times as is necessary to produce the
       
    44         *       required quantity of data. For example, if P_SHA-1 was being used to
       
    45         *       create 64 bytes of data, it would have to be iterated 4 times
       
    46         *       (through A(4)), creating 80 bytes of output data; the last 16 bytes
       
    47         *       of the final iteration would then be discarded, leaving 64 bytes of
       
    48         *       output data.
       
    49         * @param aSecret - secret
       
    50         * @param aSeed - seed
       
    51         * @param aLength - length of new secret
       
    52         * @since Series60 4.0
       
    53         */
       
    54         IMPORT_C static HBufC8* GetPSHA1HashL( const TDesC8& aSecret, 
       
    55                                                const TDesC8& aSeed, 
       
    56                                                const TInt aLength );
       
    57     
       
    58         /*
       
    59         * Encode data into Base64 format
       
    60         * @param aData - source data
       
    61         * @return encoded data, if some problem occurs, NULL is returned
       
    62         * @since Series60 4.0
       
    63         */
       
    64         IMPORT_C static HBufC8* EncodeBase64L(const TDesC8& aData);
       
    65     
       
    66         /*
       
    67         * Decode data from Base64 format
       
    68         * @param aData - source data
       
    69         * @return decoded data, if some problem occurs, NULL is returned
       
    70         * @since Series60 4.0
       
    71         */
       
    72         IMPORT_C static HBufC8* DecodeBase64L(const TDesC8& aData);
       
    73     
       
    74         /*
       
    75         * Randomize some data and hash it using MD5 digest algorithm.
       
    76         * @return hashed randomized data (constant length of hash according to MD5 specification)
       
    77         * @since Series60 4.0
       
    78         */
       
    79         IMPORT_C static HBufC8* RandomAndHashMd5LC();
       
    80         
       
    81         /*
       
    82         * Create <BinarySecret> tag from security token.
       
    83         * @param aSecret security context token.
       
    84         * @param aValueType Indicates what the security token is
       
    85         * @return <BinarySecret> tag with encoded (base64) token.
       
    86         */
       
    87         IMPORT_C static HBufC8* CreateEncodedBinarySecretL( const TDesC8& aSecret, 
       
    88                                                             const TDesC8& aValueType );
       
    89         
       
    90         /*
       
    91         * Timestamp as number of seconds since 1 january 1970 
       
    92         *   Calculated for present phone time.
       
    93         * @return timestamp value
       
    94         * @since Series60 5.0
       
    95         */
       
    96         IMPORT_C static HBufC8* GetTimestampL();
       
    97 
       
    98 
       
    99         /*
       
   100         * Timestamp as number of seconds since 1 january 1970.
       
   101         *   Calculated for provided time.
       
   102         * @param aTime base for generated timestamp
       
   103         * @return timestamp value
       
   104         * @since Series60 5.0
       
   105         */
       
   106         IMPORT_C static HBufC8* GetTimestampL(TTime aTime);
       
   107         
       
   108         /*
       
   109         * Randomize some data (based on time) and hash it using MD5 digest algorithm, 
       
   110         * convert each byte to hex nember representation
       
   111         * @return hashed randomized data (constant length of hash according to MD5 specification
       
   112         * doubled during hex conversion)
       
   113         * @since Series60 5.0
       
   114         */
       
   115         IMPORT_C static HBufC8* GetRandomNonceL();
       
   116         
       
   117     private:
       
   118         /**
       
   119         * Hide default C++ constructor.
       
   120         */
       
   121         SenCryptoUtils();
       
   122     };
       
   123 
       
   124 #endif // C_SEN_CRYPTO_UTILS_H
       
   125