Message Digest

Updated: 2021-02-21

Read more about crypto hash function here

Python

>>> hashlib.md5(b"hello").hexdigest()
'5d41402abc4b2a76b9719d911017c592'

Java

jshell> import java.security.MessageDigest

jshell> MessageDigest md = MessageDigest.getInstance("MD5")
md ==> MD5 Message Digest from SUN, <initialized>

Get digest as byte array:

jshell> byte[] a = md.digest("hello".getBytes())
a ==> byte[16] { 93, 65, 64, 42, -68, 75, 42, 118, -71, ...  -111, 16, 23, -59, -110 }

Convert the byte array to Hex String:

jshell> IntStream.range(0, a.length).mapToObj(i -> String.format("%02X", a[i])).collect(Collectors.joining())
$40 ==> "5D41402ABC4B2A76B9719D911017C592"