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

Extron RGB 202xi ADSP Universal Analog, ECL and TTL Computer-Video Interface
$35.99
Extron RGB 202xi ADSP Universal Analog, ECL and TTL Computer-Video Interface pictureCOMDYNA GP-6 ANALOG PATCH CORD COMPUTER GP6 *TESTED & WORKING*
$999.0
COMDYNA GP-6 ANALOG PATCH CORD COMPUTER GP6 *TESTED & WORKING* pictureMeasurement Computing USB-1208FS Analog Channel
$99.99
Measurement Computing USB-1208FS Analog Channel pictureExtron RGB192 (VGA) 60-486-01 Analog Computer-Video Interface **NEW In Box**
$125.0
Extron RGB192 (VGA) 60-486-01 Analog Computer-Video Interface **NEW In Box** pictureCIO-DAS08 Analog Input Board Computer Boards
$35.0
CIO-DAS08 Analog Input Board Computer Boards picture






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