Class: Vpago::PayoutProfiles::Payway::OpenSslEncrypter

Inherits:
Object
  • Object
show all
Defined in:
app/services/vpago/payout_profiles/payway/open_ssl_encrypter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, rsa_public_key:) ⇒ OpenSslEncrypter

Returns a new instance of OpenSslEncrypter.



9
10
11
12
# File 'app/services/vpago/payout_profiles/payway/open_ssl_encrypter.rb', line 9

def initialize(content:, rsa_public_key:)
  @content = content
  @rsa_public_key = OpenSSL::PKey::RSA.new(rsa_public_key)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'app/services/vpago/payout_profiles/payway/open_ssl_encrypter.rb', line 7

def content
  @content
end

#rsa_public_keyObject (readonly)

Returns the value of attribute rsa_public_key.



7
8
9
# File 'app/services/vpago/payout_profiles/payway/open_ssl_encrypter.rb', line 7

def rsa_public_key
  @rsa_public_key
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/vpago/payout_profiles/payway/open_ssl_encrypter.rb', line 14

def call
  # Assumes 1024 bit key and encrypts in chunks.
  maxlength = 117
  output = ''

  source = content.dup
  while source != ''
    input = source.slice!(0, maxlength)
    encrypted = rsa_public_key.public_encrypt(input)
    output += encrypted
  end

  Base64.strict_encode64(output)
end