def sha256Hash(text: String) : String = java.security.MessageDigest.getInstance("SHA-256").digest(text.getBytes()).map(0xFF & ).map { "%02x".format() }.foldLeft(""){_ + _}
def sha256Hash(text: String) : String = String.format("%064x", new java.math.BigInteger(1, java.security.MessageDigest.getInstance("SHA-256").digest(text.getBytes("UTF-8"))))
verify via:
scala> sha256Hash("Rusty is a cowboy!")
res3: String = e0baa113fe0dd65bc88b4144c6b12c89f362a3617644315b48b36f668f7fa1d6
I get a different result from multiple on-line hash generators.
For example:
http://www.xorbin.com/tools/sha256-hash-calculator
Rusty is a cowboy!
e0baa113fe0dd65bc88b4144c6b12c89f362a3617644315b48b36f668f7fa1d6