Module: JsonWebToken::Algorithm::Hmac
- Extended by:
- Common
- Defined in:
- lib/json_web_token/algorithm/hmac.rb
Overview
Sign or verify a JSON Web Signature (JWS) structure using HMAC with SHA-2 algorithms
Constant Summary
Constants included from Common
Class Method Summary collapse
-
.sign(sha_bits, shared_key, signing_input) ⇒ BinaryString
A digital signature, or mac.
-
.verify?(mac, sha_bits, shared_key, signing_input) ⇒ Boolean
A predicate to verify the signing_input by comparing a given
mac
to themac
for a newly signed message; comparison done in a constant-time manner to thwart timing attacks.
Methods included from Common
digest_new, validate_key, validate_sha_bits
Class Method Details
.sign(sha_bits, shared_key, signing_input) ⇒ BinaryString
Returns a digital signature, or mac.
22 23 24 25 |
# File 'lib/json_web_token/algorithm/hmac.rb', line 22 def sign(sha_bits, shared_key, signing_input) validate_key(sha_bits, shared_key) OpenSSL::HMAC.digest(digest_new(sha_bits), shared_key, signing_input) end |
.verify?(mac, sha_bits, shared_key, signing_input) ⇒ Boolean
Returns a predicate to verify the signing_input by comparing a given mac
to the mac
for a newly signed message; comparison done in a constant-time manner to thwart timing attacks.
36 37 38 |
# File 'lib/json_web_token/algorithm/hmac.rb', line 36 def verify?(mac, sha_bits, shared_key, signing_input) Util.constant_time_compare?(mac, sign(sha_bits, shared_key, signing_input)) end |