Class: Krypt::HMAC
- Inherits:
-
Object
- Object
- Krypt::HMAC
- Includes:
- Krypt::Helper::XOR
- Defined in:
- lib/krypt/hmac.rb
Class Method Summary collapse
Instance Method Summary collapse
- #digest ⇒ Object
- #hexdigest ⇒ Object
-
#initialize(digest, key) ⇒ HMAC
constructor
A new instance of HMAC.
- #update(data) ⇒ Object (also: #<<)
Methods included from Krypt::Helper::XOR
Constructor Details
#initialize(digest, key) ⇒ HMAC
Returns a new instance of HMAC.
5 6 7 8 9 10 11 |
# File 'lib/krypt/hmac.rb', line 5 def initialize(digest, key) @digest = digest @key = process_key(key) # hash ipad hash_pad(0x36) end |
Class Method Details
.digest(md, key, data) ⇒ Object
32 33 34 35 36 |
# File 'lib/krypt/hmac.rb', line 32 def digest(md, key, data) hmac = self.new(md, key) hmac << data hmac.digest end |
Instance Method Details
#digest ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/krypt/hmac.rb', line 18 def digest inner_digest = @digest.digest # hash opad hash_pad(0x5c) @digest << inner_digest @digest.digest end |
#hexdigest ⇒ Object
26 27 28 |
# File 'lib/krypt/hmac.rb', line 26 def hexdigest Krypt::Hex.encode(digest) end |
#update(data) ⇒ Object Also known as: <<
13 14 15 |
# File 'lib/krypt/hmac.rb', line 13 def update(data) @digest << data end |