class ExoBasic::HMACKeys
Constants
- SIZE
Public Class Methods
gen_key(size=nil)
click to toggle source
# File lib/exobasic/encrypt/hmac_keys.rb, line 15 def self.gen_key(size=nil) s = size.nil? ? HMACKeys::SIZE : s SecureRandom.hex(s) end
sign_message(key, data)
click to toggle source
# File lib/exobasic/encrypt/hmac_keys.rb, line 21 def self.sign_message(key, data) signature = OpenSSL::HMAC.hexdigest('SHA256', key, data) signature_base64 = Base64.encode64(signature).gsub("\n", '') signature_base64 end
verify_message(key, signature_base64, data)
click to toggle source
# File lib/exobasic/encrypt/hmac_keys.rb, line 28 def self.verify_message(key, signature_base64, data) # Hash the signatures a second time (to protect against timing attacks) and compare them Digest::SHA256.base64digest(HMACKeys.sign_message(key, data)) == Digest::SHA256.base64digest(signature_base64) end