method

new

Importance_2
new(p1, p2) public

Returns an instance of OpenSSL::HMAC set with the key and digest algorithm to be used. The instance represents the initial state of the message authentication code before any data has been processed. To process data with it, use the instance method #update with your data as an argument.

Example

key = 'key'
digest = OpenSSL::Digest.new('sha1')
instance = OpenSSL::HMAC.new(key, digest)
#=> f42bb0eeb018ebbd4597ae7213711ec60760843f
instance.class
#=> OpenSSL::HMAC

A note about comparisons

Two instances won’t be equal when they’re compared, even if they have the same value. Use #to_s or #hexdigest to return the authentication code that the instance represents. For example:

other_instance = OpenSSL::HMAC.new('key', OpenSSL::Digest.new('sha1'))
#=> f42bb0eeb018ebbd4597ae7213711ec60760843f
instance
#=> f42bb0eeb018ebbd4597ae7213711ec60760843f
instance == other_instance
#=> false
instance.to_s == other_instance.to_s
#=> true
Show source
Register or log in to add new notes.