class DIBS::HMAC
Constants
- DIBS_PARAM_NAMES
Params taken from the below urls. 2013-10-17 tech.dibs.dk/integration_methods/dibs_payment_window/parameters/ tech.dibs.dk/integration_methods/dibs_payment_window/return_pages/
Public Class Methods
calculate(params, key)
click to toggle source
# File lib/dibs/hmac.rb, line 77 def self.calculate(params, key) param_string = "" params.keys.sort.each do |key| if DIBS_PARAM_NAMES.include?(key.to_s) || key.to_s.start_with?("s_") || key.to_s.match(/oiRow[0-9]+/) value = params[key] param_string += "&" if param_string.length > 0 param_string += "#{key}=#{value}" end end OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'),Array(key).pack('H*'), param_string) end
valid?(params, key)
click to toggle source
# File lib/dibs/hmac.rb, line 90 def self.valid?(params, key) params['MAC'] || params[:MAC] == calculate(params, key) end