Sha256: 3555ecea5e88fdac127e7609ef3eb2bce1dfe4b7947c9e44fac455d62256919f

Contents?: true

Size: 686 Bytes

Versions: 6

Compression:

Stored size: 686 Bytes

Contents

# frozen_string_literal: true

require 'openssl'
require 'base64'

module Mpesa
  # Security Credentials
  class SecurityCred
    attr_reader :initiator_password, :env

    def initialize(pass, env)
      @initiator_password = pass
      @env = env
    end

    def password_credential
      raw = if env == 'production'
              File.read(File.join(File.dirname(__FILE__), '../cert/production.pem'))
            else
              File.read(File.join(File.dirname(__FILE__), '../cert/sandbox.pem'))
            end

      cert = OpenSSL::X509::Certificate.new(raw)
      key = cert.public_key
      Base64.strict_encode64(key.public_encrypt(initiator_password))
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mpesarb-0.3.5 lib/mpesa/securitycred.rb
mpesarb-0.3.4 lib/mpesa/securitycred.rb
mpesarb-0.3.3 lib/mpesa/securitycred.rb
mpesarb-0.3.2 lib/mpesa/securitycred.rb
mpesarb-0.3.1 lib/mpesa/securitycred.rb
mpesarb-0.3.0 lib/mpesa/securitycred.rb