Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HMAC-MD5 hashing algorithm

843810Sep 10 2004 — edited Sep 10 2004
Hello,
I'm semi successfull at finally creating this algorithm and running it againts the variables I need to. But it doesn't seem to be a true HMAC-MD5 hash...

The successfull hash I create with an ASP script that works and plugs into my gateway looks like this...
f81633aec015f23fbfd57bec77529c31

The one I create with the following code looks like this and has a trailing == in every one and doesn't work and I dont want to use ASP for this I would like to use java?
JN4Kuk4KFN6pO/XA/wdAWg==

Can anyone lend a hand pleeeeeeeeese...
    public static String HMAC(String values, String myKeyString){
    String output = "";
    try {
        
        PBEKeySpec keySpec = new PBEKeySpec(myKeyString.toCharArray());
        SecretKeyFactory skf = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        SecretKey key = skf.generateSecret(keySpec);
        
        //I use "hmacMD5" here becuase when I use        
        //key.getAlgorithm() it returns nothing
        Mac mac = Mac.getInstance("hmacMD5");
        mac.init(key);
    
    
        // Encode the string into bytes using utf-8 and digest it
        byte[] utf8 = values.getBytes("utf8");
        byte[] digest = mac.doFinal(utf8);
    
        // convert the digest into a string
        String digestB64 = new sun.misc.BASE64Encoder().encode(digest);
        output += digestB64;
        
        } catch (InvalidKeyException e) {
        } catch (NoSuchAlgorithmException e) {
        } catch (UnsupportedEncodingException e) {
        } catch (InvalidKeySpecException e) {
        } 
        
        return output;
    }
thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 8 2004
Added on Sep 10 2004
7 comments
431 views