class Fintecture::Utils::Crypto
Public Class Methods
create_signature_header(headers)
click to toggle source
# File lib/fintecture/utils/crypto.rb, line 55 def create_signature_header(headers) signing = [] header = [] Fintecture::Utils::Constants::SIGNEDHEADERPARAMETERLIST.each do |param| next unless headers[param] param_low = param.downcase signing << "#{param_low}: #{headers[param]}" header << param_low end # Double quote in join needed. If not we will get two slashes \\n signature = sign_payload signing.join("\n") 'keyId="' + Fintecture.app_id + '",algorithm="rsa-sha256",headers="' + header.join(' ') + '",signature="' + signature + '"' end
decrypt_private(digest)
click to toggle source
# File lib/fintecture/utils/crypto.rb, line 36 def decrypt_private(digest) digest = URI.unescape digest encrypted_string = Base64.decode64(digest) private_key = OpenSSL::PKey::RSA.new(Fintecture.private_key) begin private_key.private_decrypt(encrypted_string, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING) rescue OpenSSL::PKey::RSAError => e raise Fintecture::CryptoException.new("error while decrypt, #{e.message}") rescue raise Fintecture::CryptoException.new('error during decryption') end end
generate_uuid()
click to toggle source
# File lib/fintecture/utils/crypto.rb, line 14 def generate_uuid SecureRandom.uuid end
generate_uuid_only_chars()
click to toggle source
# File lib/fintecture/utils/crypto.rb, line 18 def generate_uuid_only_chars generate_uuid.gsub!('-','') end
hash_base64(plain_text)
click to toggle source
# File lib/fintecture/utils/crypto.rb, line 50 def hash_base64(plain_text) digest = Digest::SHA256.digest plain_text Base64.strict_encode64(digest) end
sign_payload(payload)
click to toggle source
# File lib/fintecture/utils/crypto.rb, line 22 def sign_payload(payload) payload = payload.to_json.to_s if payload.is_a? Hash digest = OpenSSL::Digest::SHA256.new private_key = OpenSSL::PKey::RSA.new(Fintecture.private_key) begin signature = private_key.sign(digest, payload) Base64.strict_encode64(signature) rescue raise Fintecture::CryptoException.new('error during signature') end end