Search code examples
hmaccrystal-lang

How to create an HMAC in crystal-lang


See the OpenSSL::HMAC documentation.

I am trying this:

require "openssl"

puts OpenSSL::HMAC.hexdigest(:sha256, "secret key", "data")

and I am getting this error:

undefined constant OpenSSL::HMAC

Other OpenSSL methods are working fine, like OpenSSL::Digest.new("SHA256").

What am I doing wrong?


Solution

  • With require "openssl" you don't require hmac. This works for me:

    require "openssl/hmac"
    
    puts OpenSSL::HMAC.hexdigest(:sha256, "secret key", "data")