Created
September 27, 2019 16:41
-
-
Save saswata-dutta/48a3ae19040159f3e7aadd5b6a693e0b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// cat payload.json | openssl sha256 -hmac 'secret' | |
import javax.crypto.Mac; | |
import javax.crypto.spec.SecretKeySpec; | |
val payload = scala.io.Source.fromFile("payload.json").mkString | |
val secret = "secret" | |
val sha256_HMAC = Mac.getInstance("HmacSHA256") | |
val secret_key = new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"); | |
sha256_HMAC.init(secret_key) | |
val hash = sha256_HMAC.doFinal(payload.getBytes()) | |
val signature = hash.map(b => "%02x".format(b)).mkString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment