Computes an authenticator as HMAC-SHA-256
The authenticator can be used at a later time to verify the provenance of the message by recomputing the HMAC over the message and then comparing it to the provided authenticator. The class provides methods for generating signatures and also has a constant-time implementation for checking them.
This is a secret key authenticator, i.e. anyone who can verify signatures can also create them.
Defined Under NamespaceClasses: SHA256State, State
Constant Summary Constants inherited from Auth Instance Method Summary collapseReturn the authenticator, as raw bytes.
Return the authenticator, as hex string.
Create instance without checking key length.
Compute authenticator for message.
primitive, sodium_constant, sodium_function, sodium_function_with_return_code, sodium_primitive, sodium_type
Methods inherited from Authauth, #auth, #key_bytes, key_bytes, #primitive, #tag_bytes, tag_bytes, #verify, verify
Constructor Details #initialize(key) ⇒ SHA25643 44 45 46 47 48 49
# File 'lib/rbnacl/hmac/sha256.rb', line 43 def initialize(key) @key = Util.check_hmac_key(key, "#{self.class} key") @state = State.new @authenticator = Util.zeros(tag_bytes) self.class.auth_hmacsha256_init(@state, key, key.bytesize) endInstance Method Details #digest ⇒ String
Return the authenticator, as raw bytes
64 65 66
# File 'lib/rbnacl/hmac/sha256.rb', line 64 def digest @authenticator end#hexdigest ⇒ String
Return the authenticator, as hex string
71 72 73
# File 'lib/rbnacl/hmac/sha256.rb', line 71 def hexdigest @authenticator.unpack("H*").last end#update(message) ⇒ Object
Compute authenticator for message
54 55 56 57 58 59
# File 'lib/rbnacl/hmac/sha256.rb', line 54 def update(message) self.class.auth_hmacsha256_update(@state, message, message.bytesize) self.class.auth_hmacsha256_final(@state.clone, @authenticator) hexdigest end
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4