4

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?

twharmon
  • 4,153
  • 5
  • 22
  • 48

1 Answers1

4

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

require "openssl/hmac"

puts OpenSSL::HMAC.hexdigest(:sha256, "secret key", "data")
Vitalii Elenhaupt
  • 7,146
  • 3
  • 27
  • 43