I am trying to replicate the following .NET code in Java
https://github.com/LogosBible/Logos.Utility/blob/master/src/Logos.Utility/GuidUtility.cs
I have written equivalent code in Java but I get different values for the final GUID/UUID
Changes I made for Java - To convert the UUID to the byte array (Step 3 in the code above) I used the following - GUID to ByteArray
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
bb.putLong(namespaceId.getMostSignificantBits());
bb.putLong(namespaceId.getLeastSignificantBits());
byte[] namespaceBytes = bb.array()
For the hashing part ( Step 4) i use apache-commons message-digest class
final MessageDigest sha = MessageDigest.getInstance("SHA-1");
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(namespaceBytes);
outputStream.write(nameBytes);
sha.update(outputStream.toByteArray());
final byte[] hash = sha.digest();
The rest of the code is completely the same.
However after going through the other questions posted here about Java's signed byte array and .NET's unsigned byte. I have logged the output I get at each point and I dont see any similarity in the outputs at both these steps.
After reading through a few threads, Ive realized that the GUID.toByteArray() method works differently from the way I am converting the value in java. Also the byte array in .NET is unsigned, a type which is not supported in Java. How can I fix the code to get it to work for Java?