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

PLE 40Mhz Crystal Oscillator 40.000000 Mhz Half Can NEW Amiga Apple PC
$2.75
PLE 40Mhz Crystal Oscillator 40.000000 Mhz Half Can NEW Amiga Apple PC pictureNEW Motorola MC68030RC40B 40Mhz PGA 128 Pin Gold Amiga Apple CPU MMU Processor
$37.95
NEW Motorola MC68030RC40B 40Mhz PGA 128 Pin Gold Amiga Apple CPU MMU Processor pictureRARE Western Digital WD33C93A-PL Proto SCSI IC NEW Leftover for Amiga 3000 Etc
$64.95
RARE Western Digital WD33C93A-PL Proto SCSI IC NEW Leftover for Amiga 3000 Etc pictureSaronix 33Mhz Crystal Oscillator 33.3000 Mhz Half Can NEW Amiga Apple PC NOS
$2.75
Saronix 33Mhz Crystal Oscillator 33.3000 Mhz Half Can NEW Amiga Apple PC NOS pictureATL HDI 1000 PCB ASSY, Amiga Mboard 7500-1318-01 c A4000t
$784.0
ATL HDI 1000 PCB ASSY, Amiga Mboard 7500-1318-01 c A4000t picture






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