Remove trailing whitespaces and tabs
parent
442be992a0
commit
16a5ad5930
|
@ -65,50 +65,50 @@ class PaiementCic
|
|||
end
|
||||
|
||||
# Check if the HMAC matches the HMAC of the data string
|
||||
def valid_hmac?(mac_string, sent_mac)
|
||||
computeHMACSHA1(mac_string) == sent_mac.downcase
|
||||
end
|
||||
def valid_hmac?(mac_string, sent_mac)
|
||||
computeHMACSHA1(mac_string) == sent_mac.downcase
|
||||
end
|
||||
|
||||
# Return the HMAC for a data string
|
||||
def computeHMACSHA1(data)
|
||||
hmac_sha1(usable_key(self), data).downcase
|
||||
end
|
||||
def computeHMACSHA1(data)
|
||||
hmac_sha1(usable_key(self), data).downcase
|
||||
end
|
||||
|
||||
def hmac_sha1(key, data)
|
||||
length = 64
|
||||
length = 64
|
||||
|
||||
if (key.length > length)
|
||||
key = [Digest::SHA1.hexdigest(key)].pack("H*")
|
||||
end
|
||||
if (key.length > length)
|
||||
key = [Digest::SHA1.hexdigest(key)].pack("H*")
|
||||
end
|
||||
|
||||
key = key.ljust(length, 0.chr)
|
||||
ipad = ''.ljust(length, 54.chr)
|
||||
opad = ''.ljust(length, 92.chr)
|
||||
key = key.ljust(length, 0.chr)
|
||||
ipad = ''.ljust(length, 54.chr)
|
||||
opad = ''.ljust(length, 92.chr)
|
||||
|
||||
k_ipad = key ^ ipad
|
||||
k_opad = key ^ opad
|
||||
k_ipad = key ^ ipad
|
||||
k_opad = key ^ opad
|
||||
|
||||
#Digest::SHA1.hexdigest(k_opad + [Digest::SHA1.hexdigest(k_ipad + sData)].pack("H*"))
|
||||
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new("sha1"), key, data)
|
||||
end
|
||||
#Digest::SHA1.hexdigest(k_opad + [Digest::SHA1.hexdigest(k_ipad + sData)].pack("H*"))
|
||||
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new("sha1"), key, data)
|
||||
end
|
||||
|
||||
private
|
||||
# Return the key to be used in the hmac function
|
||||
def usable_key(payement)
|
||||
# Return the key to be used in the hmac function
|
||||
def usable_key(payement)
|
||||
|
||||
hex_string_key = payement.hmac_key[0..37]
|
||||
hex_final = payement.hmac_key[38..40] + "00";
|
||||
hex_string_key = payement.hmac_key[0..37]
|
||||
hex_final = payement.hmac_key[38..40] + "00";
|
||||
|
||||
cca0 = hex_final[0].ord
|
||||
cca0 = hex_final[0].ord
|
||||
|
||||
if cca0 > 70 && cca0 < 97
|
||||
hex_string_key += (cca0 - 23).chr + hex_final[1..2]
|
||||
elsif hex_final[1..2] == "M"
|
||||
hex_string_key += hex_final[0..1] + "0"
|
||||
else
|
||||
hex_string_key += hex_final[0..2]
|
||||
end
|
||||
if cca0 > 70 && cca0 < 97
|
||||
hex_string_key += (cca0 - 23).chr + hex_final[1..2]
|
||||
elsif hex_final[1..2] == "M"
|
||||
hex_string_key += hex_final[0..1] + "0"
|
||||
else
|
||||
hex_string_key += hex_final[0..2]
|
||||
end
|
||||
|
||||
[hex_string_key].pack("H*")
|
||||
end
|
||||
[hex_string_key].pack("H*")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue