Skip to content

Instantly share code, notes, and snippets.

@iamd3vil
Created February 23, 2016 18:14
Show Gist options
  • Save iamd3vil/5c3891c7bb446a193d45 to your computer and use it in GitHub Desktop.
Save iamd3vil/5c3891c7bb446a193d45 to your computer and use it in GitHub Desktop.
Hmac in Elixir
secret_key = "secret-key"
text = "This is a secret"
hmac = :crypto.hmac(:sha, secret_key, text)
|> Base.encode16
|> String.downcase
IO.puts "HMAC is #{hmac}" # HMAC is 08dc7014b3e778a44af52ea7a16a973a9b48f0dd
@yuriploc
Copy link

yuriploc commented Oct 1, 2024

secret_key = "secret-key"
text = "This is a secret"

hmac = :crypto.mac(:hmac, :sha256, secret_key, text) |> Base.encode16 |> String.downcase
IO.puts "HMAC is #{hmac}" # HMAC is 4ffd53df11c621f0efdb3e49c09d209b65f43abe8b60a67d1fa3716d2d0ff314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment