Created
April 20, 2023 10:14
-
-
Save aartajew/9ef60f8baac820ccbdb62430b4a79908 to your computer and use it in GitHub Desktop.
Scala > Calculate SHA-256 for a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util | |
import java.math._ | |
import java.security._ | |
object Sha256 { | |
def encode(raw: String): String = { | |
String.format("%032x", new BigInteger(1, MessageDigest.getInstance("SHA-256").digest(raw.getBytes("UTF-8")))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment