I am using consuming a C# web services and one of the parameters is sending a md5 hash. Java creates MD5 hash with signed (contains negative number in the byte array) and C# generates unsigned (contains no negative number in the byte array).
I have gone through multiple similar question in Stack Overflow but did not find any to my satisfaction.
All I need is unsigned byte array similar to the one c# generates. I have tried using BigInteger but I need it in an unsigned byte array since I need do further processing after that. BigInteger gives me one single integer and using tobytearray() still has negative numbers.
If I have to do 2 complement, then how can I do that. Then I can loop through the byte array and convert negative number to positive number.
I am using the following Java code for generating MD5 hash:
String text = "abc";
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] md5hash = new byte[32];
try {
md.update(text.getBytes("utf-8"), 0, text.length());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
md5hash = md.digest();