digest/hmac.rb
An experimental implementation of HMAC keyed-hashing algorithm
Overview
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.
Examples
require 'digest/hmac'
# one-liner example
puts Digest::HMAC.hexdigest("data", "hash key", Digest::SHA1)
# rather longer one
hmac = Digest::HMAC.new("foo", Digest::RMD160)
buf = ""
while stream.read(16384, buf)
  hmac.update(buf)
end
puts hmac.bubblebabble
    Methods
    - #
 - B
 - D
 - I
 - N
 - R
 - U
 
Class Public methods
      
        
            
              new(key, digester)
            
            Link
          
          
          
            Creates a Digest::HMAC instance.
# File ext/digest/lib/digest/hmac.rb, line 50 def initialize(key, digester) @md = digester.new block_len = @md.block_length if key.bytesize > block_len key = @md.digest(key) end ipad = Array.new(block_len, 0x36) opad = Array.new(block_len, 0x5c) key.bytes.each_with_index { |c, i| ipad[i] ^= c opad[i] ^= c } @key = key.freeze @ipad = ipad.pack('C*').freeze @opad = opad.pack('C*').freeze @md.update(@ipad) end
Instance Public methods
      
        
        
        
            
              hmac.block_length → Integer
            
            Link
          
          
          
            Returns the block length in bytes of the hmac.
            
              hmac.digest_length → Integer
            
            Link
          
          
          
            Returns the length in bytes of the hash value of the digest.
            
              hmac.inspect → string
            
            Link
          
          
          
            Creates a printable version of the hmac object.
            
              hmac.reset → hmac
            
            Link
          
          
          
            Resets the hmac to the initial state and returns self.