views:

87

answers:

2

I am trying to Sip Register and I get the challenge from the server.

So I need to use the MD5 algorithm on the nonce and then send that to the server to authenticate.

I have come across two examples of MD5 encryption and I have tried both and each one gives a different string back to me, so I was wondering which one is the correct one to use?

Thanks in advance

EDIT:

Ok thanks for the commons codecs.

I have edited it because I have to encode the nonce value I get back from the server with my username and password to send it back.

So it is a particuler type of encoding for SIP registration, can anyone point to a tutorial on how to do this? Or have any hints?

+1  A: 

One obvious problem with the first one is that you produce the hex string the wrong way. When any value in messageDigest is less than 16, then you'll produce a single-digit hex string (for example A) instead of a two-digit one (0A).

Joachim Sauer
+2  A: 

Both are incorrect. Your conversion from the byte array to a hexadecimal string is broken. I highly recommend using http://commons.apache.org/codec/ from the ASF which can do this for you:

Hex.encodeHexString(yourByteArray);

But if you're using commons-codec, you can also do this:

String sessionid = "1ddfdf99abfe5690dc1243875";
String md5HexString = DigestUtils.md5Hex(sessionid);

and you're done. Neat, isn't it? :-)

Malax
Whats the best way to do it without using the commons codec though? Not sure on the licencing of the commons codec
Donal Rafferty
Apache Commons are liceneced under the Apache Licence which should not cause any harm. http://commons.apache.org/license.html or, if you prefer the Wikipedia entry without legalse: http://en.wikipedia.org/wiki/Apache_License
Malax