开发者

digest/hmac is part of ruby standard lib

i'm working with some codes that has a:

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 its not part of the standard lib. Is it part from t开发者_JAVA技巧he ruby 1.9 lib? If not, should i install any gem?

Note that solutions using OpenSSL won't be accepted because it will fail anyway in "require 'digest/hmac'"

The code in question is here http://github.com/quetzall/cloud_cache/blob/master/lib/cloud_cache.rb


It's available in 1.8.7. Try this:

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")


From the 1.9.3 docs:

CAUTION: Use of this library is discouraged, because this implementation was meant to be experimental but somehow got into the 1.9 series without being noticed. Please use OpenSSL::HMAC in the “openssl” library instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜