Class: SecureNative::Utils::SignatureUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/securenative/utils/signature_utils.rb

Constant Summary collapse

SIGNATURE_HEADER =
'x-securenative'

Class Method Summary collapse

Class Method Details

.valid_signature?(api_key, payload, header_signature) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
# File 'lib/securenative/utils/signature_utils.rb', line 8

def self.valid_signature?(api_key, payload, header_signature)
  key = api_key.encode('utf-8')
  body = payload.encode('utf-8')
  calculated_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha512'), key, body)
  calculated_signature.eql? header_signature
rescue StandardError
  false
end