I am trying to Sip Register and I get the challenge from the server.
So I n开发者_StackOverflow中文版eed 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?
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? :-)
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
).
精彩评论