Skip to content

Instantly share code, notes, and snippets.

@phucnh
Forked from ohac/hmacsha1.scala
Last active August 29, 2015 14:26
Show Gist options
  • Save phucnh/0afda05bab2d8f89d2e6 to your computer and use it in GitHub Desktop.
Save phucnh/0afda05bab2d8f89d2e6 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