Method: HMAC::Base#set_key
- Defined in:
- lib/hmac.rb
#set_key(key) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hmac.rb', line 35 def set_key(key) # If key is longer than the block size, apply hash function # to key and use the result as a real key. key = @algorithm.digest(key) if key.size > @block_size key_xor_ipad = "\x36" * @block_size key_xor_opad = "\x5C" * @block_size for i in 0 .. key.size - 1 key_xor_ipad[i] ^= key[i] key_xor_opad[i] ^= key[i] end @key_xor_ipad = key_xor_ipad @key_xor_opad = key_xor_opad @md = @algorithm.new @status = STATUS_INITIALIZED end |