×

Discussion Board

Results 1 to 10 of 10

Hybrid View

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    12

    validation using HMac

    i am trying to validate the responce which i got from server. but i am not getting how to do?? i am referring this link but this's something different than the method used in server side MAC generation code.

    Java code:
    Code:
      public static byte[] generateMac(byte[] key, byte[] cipherText,int offset,int length, int mac_size_bits){
        	byte[] result = null;
        	KeyParameter keyParam = null;
        	try {
        		keyParam = new KeyParameter(key);
        		CBCBlockCipherMac blockCipherMac = new CBCBlockCipherMac(new AESEngine(),mac_size_bits);
        		result = new byte[blockCipherMac.getMacSize()];
        		blockCipherMac.init(keyParam);
        		blockCipherMac.update(cipherText, offset, length);
        		blockCipherMac.doFinal(result, 0);
        	} catch (Exception e) {
    //    		System.out.println(e);
        		return null;
        	}finally{
        		keyParam = null;
        	}
        	return result;
        }
    anybody suggest me what i have to change and which function to use to generate MAC key correctly.
    Thank you.
    Last edited by priya_ps; 2012-09-03 at 12:51.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,672

    Re: validation using HMac

    You may want to check if existing libraries, like https://github.com/simonpk/j2me-oauth, can help.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    12

    Re: validation using HMac

    but that's java libraries and i want to know weather i can use CBCMode as used by java to generate MAC key in symbian.
    I am doing like this now
    Code:
    TBool CRSAContainerView::HandleOpen_SSLMenuItemSelectedL( TInt aCommand )
    	{
    	// TODO: implement selected event handler
    	_LIT8(Glb_mac_Hex,"1c23f5a1ad703ed9ce60944b2796325e");
    	_LIT8(Enc_data_Hex,	"a956ae74add99adf2781fee622ffeca6");
    //	PBKDF2 (_L8("a956ae74add99adf2781fee622ffeca6"),32); 
    
    	//MAC validation
    	CSHA1* sha=CSHA1::NewL();
    
    //	TBuf8<100> keyVal;
    //	keyVal.Copy(_L8("Place your key value here"));
    	HBufC8 *keyVal;
    	keyVal = HexToBufLC(Glb_mac_Hex);
    	HBufC8 *EncDat;
    	EncDat = HexToBufLC(Enc_data_Hex);
    	int EncDatL = EncDat->Des().Length();
    	
    	CHMAC* hmac=CHMAC::NewL(keyVal->Des(),sha);
    	TInt block_size = hmac->BlockSize();
    	TInt MsgDL = hmac->HashSize();
    	TBuf8<1024> baseString;
    	baseString.Copy(EncDat->Des());
    	TPtrC8 hashedSig(hmac->Hash(baseString));
    	HBufC8* buf = HBufC8::NewL(hashedSig.Length() * 2);
    	buf->Des().Copy(hashedSig);
    	TInt bufL = buf->Des().Length();
                    HBufC8* MacHex = BufTOHex(buf->Des());
    
    //same as above    
    /*	CHMAC* hmac1=CHMAC::NewL(keyVal->Des(),sha);
    	hmac1->Update(EncDat->Des());
    	HBufC8* iSalt = HBufC8::NewL(200);
    	iSalt->Des().Copy(hmac1->Final());
    	TInt iSaltL = iSalt->Des().Length();
    */	
    //	TImCodecB64 b64enc;
    //	b64enc.Initialise();
    //	TBuf8<512> result;
    //	// encode your signature into base64 or encoding scheme required
    //	b64enc.Encode(buf->Des(),result);
    	 
    	if(hmac)
    	  {
    	  delete hmac;
    	  hmac=NULL;
    	  }
    	
    	return ETrue;
    	}
    Here it'll generate MAC of length 20. but in java its 4,8..... so i cant validate by comparing.
    i am in confusion can you pls give brief idea on this.

    Thank you

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    12

    Re: validation using HMac

    I found some details about CBC MAC(AES MAC) in these links
    http://en.wikipedia.org/wiki/CBC-MAC
    http://www.cs.berkeley.edu/~jonah/bc...CipherMac.html
    so in symbian which class i have to use to generate same kind of MAC??

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    12

    Re: validation using HMac

    No response??

    I am stuck with this. anybody please shed some light on this.
    After a long search i found this class CryptoSpi::CMacFactory but dont know weather i'll get the expected result from this and this class is not there in s60 3rd FP1. from where i can get CryptoSpi?? is there any API avilable to download??

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,672

    Re: validation using HMac

    If some API-s are missing, you can try getting them from http://www.developer.nokia.com/Commu...ptography_APIs

Similar Threads

  1. Replies: 3
    Last Post: 2008-07-22, 06:34
  2. How to Implement HMAC
    By naresh99 in forum Symbian User Interface
    Replies: 1
    Last Post: 2007-01-31, 11:06
  3. How to Implement HMAC
    By naresh99 in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-01-31, 09:57
  4. HMAC Problems
    By Neo` in forum Smart Messaging
    Replies: 0
    Last Post: 2004-09-28, 10:03

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×