Module: GpWebpay::OpensslSecurity

Defined in:
lib/gp_webpay/openssl_security.rb

Class Method Summary collapse

Class Method Details

.generate_digest(configuration, digest_text) ⇒ Object



3
4
5
6
7
# File 'lib/gp_webpay/openssl_security.rb', line 3

def self.generate_digest(configuration, digest_text)
  private_pem = OpenSSL::PKey::RSA.new(configuration.merchant_pem, configuration.merchant_password)
  sign = private_pem.sign(OpenSSL::Digest.new('SHA1'), digest_text)
  Base64.encode64(sign).gsub("\n", '')
end

.validate_digests(configuration, data) ⇒ Object



9
10
11
12
13
14
# File 'lib/gp_webpay/openssl_security.rb', line 9

def self.validate_digests(configuration, data)
  public_pem = OpenSSL::X509::Certificate.new(configuration.gpe_pem).public_key
  data.all? do |received, expected|
    public_pem.verify(OpenSSL::Digest.new('SHA1'), Base64.decode64(received), expected)
  end
end