Class: CyberSource::TokenVerification
- Inherits:
-
Object
- Object
- CyberSource::TokenVerification
- Defined in:
- lib/cybersource_rest_client/utilities/flex/token_verification.rb
Instance Method Summary collapse
-
#CamelCasetoUnderscore(str) ⇒ Object
Converting response field from camelCase to Underscore.
- #verifyToken(public_key, post_param) ⇒ Object
Instance Method Details
#CamelCasetoUnderscore(str) ⇒ Object
Converting response field from camelCase to Underscore
34 35 36 37 38 39 40 |
# File 'lib/cybersource_rest_client/utilities/flex/token_verification.rb', line 34 def CamelCasetoUnderscore(str) str.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |
#verifyToken(public_key, post_param) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cybersource_rest_client/utilities/flex/token_verification.rb', line 3 def verifyToken(public_key, post_param) post_param = JSON.parse(post_param) signed_fields = Array.new get_signed_fields = Array.new signed_values = "" signature = "" if post_param['signedFields'].to_s.empty? raise StandardError.new("Missing required field: signed_fields") else signed_fields = post_param['signedFields'].split(',') end signed_fields.each do |value| signed_values << ',' signed_values << post_param[value].to_s end if signed_values.length > 0 signed_values.slice!(0) end if post_param['signature'].to_s.empty? raise StandardError.new("Missing required field: signature") else signature = post_param['signature'] end string_to_pem = Base64.decode64(public_key) public_key_to_pem = OpenSSL::PKey::RSA.new(string_to_pem) verify = public_key_to_pem.verify(OpenSSL::Digest::SHA512.new, Base64.decode64(signature), signed_values) rescue StandardError => err raise err end |