final static String HMAC_MD5(byte[] key,byte[] text) throws NoSuchAlgorithmException {
  MessageDigest md5=MessageDigest.getInstance("MD5");
  if (key.length > MD5_BLOCKSIZE) {
    key=md5.digest(key);
  }
  byte[] ipad=new byte[MD5_BLOCKSIZE];
  byte[] opad=new byte[MD5_BLOCKSIZE];
  byte[] digest;
  int i;
  for (i=0; i < key.length; i++) {
    ipad[i]=key[i];
    opad[i]=key[i];
  }
  for (i=0; i < MD5_BLOCKSIZE; i++) {
    ipad[i]^=0x36;
    opad[i]^=0x5c;
  }
  md5.update(ipad);
  md5.update(text);
  digest=md5.digest();
  md5.update(opad);
  md5.update(digest);
  digest=md5.digest();
  StringBuffer digestString=new StringBuffer();
  for (i=0; i < digest.length; i++) {
    if ((digest[i] & 0x000000ff) < 0x10) {
      digestString.append("0" + Integer.toHexString(digest[i] & 0x000000ff));
    }
 else {
      digestString.append(Integer.toHexString(digest[i] & 0x000000ff));
    }
  }
  Arrays.fill(ipad,(byte)0);
  Arrays.fill(opad,(byte)0);
  ipad=null;
  opad=null;
  return (digestString.toString());
}

final static String HMAC_MD5 ( byte [ ] key , byte [ ] text ) throws NoSuchAlgorithmException { MessageDigest md5 = MessageDigest . getInstance ( "MD5" ) ; if ( key . length > MD5_BLOCKSIZE ) { key = md5 . digest ( key ) ; } byte [ ] ipad = new byte [ MD5_BLOCKSIZE ] ; byte [ ] opad = new byte [ MD5_BLOCKSIZE ] ; byte [ ] digest ; int i ; for ( i = 0 ; i < key . length ; i ++ ) { ipad [ i ] = key [ i ] ; opad [ i ] = key [ i ] ; } for ( i = 0 ; i < MD5_BLOCKSIZE ; i ++ ) { ipad [ i ] ^= 0x36 ; opad [ i ] ^= 0x5c ; } md5 . update ( ipad ) ; md5 . update ( text ) ; digest = md5 . digest ( ) ; md5 . update ( opad ) ; md5 . update ( digest ) ; digest = md5 . digest ( ) ; StringBuffer digestString = new StringBuffer ( ) ; for ( i = 0 ; i < digest . length ; i ++ ) { if ( ( digest [ i ] & 0x000000ff ) < 0x10 ) { digestString . append ( "0" + Integer . toHexString ( digest [ i ] & 0x000000ff ) ) ; } else { digestString . append ( Integer . toHexString ( digest [ i ] & 0x000000ff ) ) ; } } Arrays . fill ( ipad , ( byte ) 0 ) ; Arrays . fill ( opad , ( byte ) 0 ) ; ipad = null ; opad = null ; return ( digestString . toString ( ) ) ; }
hashes its input arguments according to hmac - md5 ( rfc 2104 ) and returns the resulting digest in its ascii representation . hmac - md5 function is described as follows : md5 ( key xor opad , md5 ( key xor ipad , text ) ) where key is an n byte key ipad is the byte 0x36 repeated 64 times opad is the byte 0x5c repeated 64 times text is the data to be protected
