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

8 x CM 8164 DRAM 64kx1 164 4864 IC Apple IIe Commodore 64 Oric IBM PC Soviet Era
$9.99
8 x CM 8164 DRAM 64kx1 164 4864 IC Apple IIe Commodore 64 Oric IBM PC Soviet Era pictureComfortable Commodore II Oversize Leather Chair with Adjustable Headrest, New
$249.99
Comfortable Commodore II Oversize Leather Chair with Adjustable Headrest, New pictureNEW 8x FUJITSU MB8264A -15 DRAM 64kx1 164 4864 IC Apple II Commodore Oric IBM PC
$11.99
NEW 8x FUJITSU MB8264A -15 DRAM 64kx1 164 4864 IC Apple II Commodore Oric IBM PC pictureVintage Commodore Typewriter 1960's Simpson’s Canada with Case
$41.35
Vintage Commodore Typewriter 1960's Simpson’s Canada with Case pictureJelenko Commodore VPF Porcelain Oven with Vaccum Pump and Extras
$875.0
Jelenko Commodore VPF Porcelain Oven with Vaccum Pump and Extras picture






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