diff --git a/lib/openid/cryptutil.rb b/lib/openid/cryptutil.rb index 98e49b36..66c97372 100644 --- a/lib/openid/cryptutil.rb +++ b/lib/openid/cryptutil.rb @@ -2,7 +2,7 @@ require "digest/sha1" require "digest/sha2" begin - require "digest/hmac" + require "openssl" rescue LoadError begin # Try loading the ruby-hmac files if they exist @@ -37,8 +37,8 @@ def CryptUtil.sha1(text) end def CryptUtil.hmac_sha1(key, text) - if Digest.const_defined? :HMAC, false - Digest::HMAC.new(key,Digest::SHA1).update(text).digest + if defined? OpenSSL + OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, key, text) else return HMAC::SHA1.digest(key, text) end @@ -49,8 +49,8 @@ def CryptUtil.sha256(text) end def CryptUtil.hmac_sha256(key, text) - if Digest.const_defined? :HMAC, false - Digest::HMAC.new(key,Digest::SHA256).update(text).digest + if defined? OpenSSL + OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, key, text) else return HMAC::SHA256.digest(key, text) end