def hash_string(s):
hsh = bytearray(hashlib.md5(s.encode(encoding="ascii")).digest())
assert len(hsh) == 16
output = \
int.from_bytes(hsh[0:4], "big") ^ \
int.from_bytes(hsh[4:8], "big") ^ \
int.from_bytes(hsh[8:12], "big") ^ \
int.from_bytes(hsh[12:16], "big")
return binascii.hexlify(output.to_bytes(4, byteorder='big')).decode("ascii")
I want to do the same in Java. However I am stuck because I am not sure how to proceed after creating the hash. Below is my code in java
private static String hashString(String s) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(s.getBytes());
byte[] digest = md.digest();
System.out.println("Length of hash after md5" +digest.length);
String myHash = DatatypeConverter.printHexBinary(digest).toUpperCase();
System.out.println("Length of the stirng" +myHash.getBytes().length);
return myHash;
}