This is just an analog of this java code, but without StringBuilder (it is up to you)
MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
String password = "secret";
messageDigest.update(password.getBytes());
byte[] bytes = messageDigest.digest();
StringBuilder stringBuilder = new StringBuilder();
for (byte aByte : bytes) {
stringBuilder.append(Integer.toString((aByte & 0xff) + 0x100, 16).substring(1));
}
System.out.println(stringBuilder.toString());
Consider the second line:
md.digest(inputStr.getBytes()).map(0xFF & _).map { "%02x".format(_) }.foldLeft("") {_ + _}
- md.digest (inputStr.getBytes ()) ---- take bytes from a string
- md.digest (inputStr.getBytes ()). map (0xFF and _) --- bitwise and with each element of the array (the map returns a new array)
- md.digest(inputStr.getBytes()). map (0xFF ). map { "% 02x".format()} .
- md.digest(inputStr.getBytes()). map (0xFF ).map { "% 02x".format()}. foldLeft ( ") {_ + _} it , , " ", ( , " " StringBuilder, ). , .. scala. https://coderwall.com/p/4l73-a/scala-fold-foldleft-and-foldright