Skip to content

Instantly share code, notes, and snippets.

@aartajew
Created April 20, 2023 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aartajew/9ef60f8baac820ccbdb62430b4a79908 to your computer and use it in GitHub Desktop.
Save aartajew/9ef60f8baac820ccbdb62430b4a79908 to your computer and use it in GitHub Desktop.
Scala > Calculate SHA-256 for a string
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