Digest / hmac is part of the ruby ​​standard lib

I work with some codes that have:

begin require 'digest/hmac' USE_EMBEDDED_HMAC = false rescue puts "HMAC, not found in standard lib." + $!.message require 'hmac-sha1' USE_EMBEDDED_HMAC = true end 


As I could see, at least in rails 1.8.6 it was not part of the standard lib. Is this part from ruby ​​1.9 lib? If not, should I install any stone?

Please note that decisions using OpenSSL will not be made, because it will still “require” digest / hmac "

This code is here http://github.com/quetzall/cloud_cache/blob/master/lib/cloud_cache.rb

+7
ruby hmac gem
source share
2 answers

It is available in 1.8.7. Try the following:

 ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9] require 'openssl' digest = OpenSSL::Digest::Digest.new('sha1') OpenSSL::HMAC.digest(digest, "superscret", "Lorem ipsum dolor sit amet") OpenSSL::HMAC.hexdigest(digest, "superscret", "Lorem ipsum dolor sit amet") 
+18
source share

From 1.9.3 docs :

CAUTION: Using this library is not recommended, as this implementation should have been experimental, but somehow got into the 1.9 series without noticing it. Instead, use OpenSSL :: HMAC in the "openssl" library.

+7
source share

All Articles