BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 06-06-2011, 05:50 AM   #1 (permalink)
New Member
 
Join Date: Jun 2011
Model: 8250
PIN: N/A
Carrier: Developer
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default [Help] XMPP Digest-MD5

Please Login to Remove!

Dear all developers,
i'm newbie blackberry developer. i am developing messenger application using xmpp. i got problem when server send me a challenge and response it back. at bellow was my code. i don't know why it's get error when want to read...

Code:
MD5Digest digest = new MD5Digest();
digest.update(username.getBytes(charset));
digest.update(":".getBytes());
digest.update(host.getBytes());
digest.update(":".getBytes());
digest.update(password.getBytes(charset));
byte[] buffer = new byte[digest.getDigestLength()];
digest.getDigest(buffer, offset);
message = convertToHex(buffer);
			
digest.reset();
digest.update(message.getBytes());
digest.update(":".getBytes());
digest.update(nonce.getBytes());
digest.update(":".getBytes());
digest.update(cnonce.getBytes());
digest.update(":".getBytes());
digest.update(myjid.getBytes(charset));
buffer = new byte[digest.getDigestLength()];
digest.getDigest(buffer, offset);
String ha1 = convertToHex(buffer);
			
digest.reset();
digest.update("AUTHENTICATE:".getBytes());
digest.update(digestUri.getBytes());
buffer = new byte[digest.getDigestLength()];
digest.getDigest(buffer, offset);
String ha2 = convertToHex(buffer);
			
digest.reset();
digest.update(ha1.getBytes());
digest.update(":".getBytes());
digest.update(nonce.getBytes());
digest.update(":".getBytes());
digest.update(nc.getBytes());
digest.update(":".getBytes());
digest.update(qop.getBytes());
digest.update(":".getBytes());
digest.update(ha2.getBytes());
buffer = new byte[digest.getDigestLength()];
digest.getDigest(buffer, offset);
message = convertToHex(buffer);
			
message = "username=\""+username+"\", realm=\""+host+"\", nonce=\""+nonce+"\", cnonce=\""+
				cnonce+"\", nc="+nc+", qop="+qop+", digest-uri=\""+digestUri+"\", response="+message+", charset="+charset+", authzid=\""+myjid+"\"";
message = Base64.encode(message.getBytes());
			
os.write(message.getBytes());
os.flush();

	private static String convertToHex(byte[] buffer) {
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < buffer.length; i++) {
            int halfbyte = (buffer[i] >>> 4) & 0x0F;
            int two_halfs = 0;
            do {
                if ((0 <= halfbyte) && (halfbyte <= 9))
                    buf.append((char) ('0' + halfbyte));
                else
                    buf.append((char) ('a' + (halfbyte - 10)));
                halfbyte = buffer[i] & 0x0F;
            } while(two_halfs++ < 1);
        }
        return buf.toString();
    }

Last edited by chanzdevilz : 06-06-2011 at 06:03 AM.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads for: [Help] XMPP Digest-MD5
Thread Thread Starter Forum Replies Last Post
md5 hashing and MD5Digest revisited goelectric Developer Forum 1 05-09-2008 06:53 AM
http digest authentication wang_hai2000 Developer Forum 6 02-19-2008 05:01 PM
md5 hashing bemshaswing Developer Forum 2 08-22-2007 11:05 PM

VoIP Intercom w/Keypad - Wall Mount
$545.86
VoIP Intercom w/Keypad - Wall Mount pictureVoIP Outdoor Intercom w/ Keypad
$683.86
VoIP Outdoor Intercom w/ Keypad pictureVoIP Intercom w/Keypad - Flush Mount
$545.86
VoIP Intercom w/Keypad - Flush Mount picture2 x Polycom CX600 IP VoIP Office Phone 2201-15942-001 No Headsets
$30.0
2 x Polycom CX600 IP VoIP Office Phone 2201-15942-001 No Headsets pictureLot of 5 Cisco CP-7941G IP Phone 7941 VoIP Business Phone + handsets
$79.36
Lot of 5 Cisco CP-7941G IP Phone 7941 VoIP Business Phone + handsets picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.