Skip to content

Instantly share code, notes, and snippets.

@ohac
Created February 22, 2010 09:00
Show Gist options
  • Save ohac/310945 to your computer and use it in GitHub Desktop.
Save ohac/310945 to your computer and use it in GitHub Desktop.
HMAC-SHA1 for Scala
import javax.crypto.spec.SecretKeySpec
import javax.crypto.Mac
object A {
def main(args: Array[String]): Unit = {
val secret = new SecretKeySpec("the_secret".getBytes, "HmacSHA1")
val mac = Mac.getInstance("HmacSHA1")
mac.init(secret)
val result: Array[Byte] = mac.doFinal("foo".getBytes)
println(result.map(_.toString).mkString(","))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment