twharmon
twharmon

Reputation: 4282

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?

Upvotes: 4

Views: 314

Answers (1)

Vitalii Elenhaupt
Vitalii Elenhaupt

Reputation: 7326

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

require "openssl/hmac"

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

Upvotes: 4

Related Questions