A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://rubydoc.info/github/cryptosphere/rbnacl/RbNaCl/HMAC/SHA256 below:

SHA256 – Documentation for cryptosphere/rbnacl (main) – RubyDoc.info

Class: RbNaCl::HMAC::SHA256
Inherits:
Auth show all
Extended by:
Sodium
Defined in:
lib/rbnacl/hmac/sha256.rb
Overview

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 Namespace

Classes: SHA256State, State

Constant Summary Constants inherited from Auth

Auth::BYTES, Auth::KEYBYTES

Instance Method Summary collapse Methods included from Sodium

primitive, sodium_constant, sodium_function, sodium_function_with_return_code, sodium_primitive, sodium_type

Methods inherited from Auth

auth, #auth, #key_bytes, key_bytes, #primitive, #tag_bytes, tag_bytes, #verify, verify

Constructor Details #initialize(key) ⇒ SHA256
43
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)
end
Instance 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