Class: SecupayRuby::ApiKey::SubKey

Inherits:
Object
  • Object
show all
Defined in:
lib/secupay_ruby/api_key/sub_key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ciphertext:, iv:, mac:, project_name:, contract_id:, payin_account: {}) ⇒ SubKey

Changing “iv”, “mac” or “project_name” will cause a bad decrypt when getting key!



11
12
13
14
15
16
17
18
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 11

def initialize(ciphertext:, iv:, mac:, project_name:, contract_id: , payin_account: {})
  @ciphertext = ciphertext
  @iv = iv
  @project_name = project_name
  @mac = mac
  self.contract_id = contract_id
  self. = 
end

Instance Attribute Details

#ciphertextObject (readonly)

Returns the value of attribute ciphertext.



7
8
9
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 7

def ciphertext
  @ciphertext
end

#contract_idObject

Returns the value of attribute contract_id.



8
9
10
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 8

def contract_id
  @contract_id
end

#ivObject (readonly)

Returns the value of attribute iv.



7
8
9
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 7

def iv
  @iv
end

#macObject (readonly)

Returns the value of attribute mac.



7
8
9
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 7

def mac
  @mac
end

#payin_accountObject

Returns the value of attribute payin_account.



8
9
10
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 8

def 
  
end

#project_nameObject (readonly)

Returns the value of attribute project_name.



7
8
9
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 7

def project_name
  @project_name
end

Class Method Details

.cipherObject



67
68
69
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 67

def cipher
  OpenSSL::Cipher.new("aes-128-gcm")
end

.generate_secure_keyObject



57
58
59
60
61
62
63
64
65
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 57

def generate_secure_key
  @secure_key ||= begin
    pass = SecupayRuby.config.api_key
    salt = "dflkhjfdgljhndgjlbnskjdbkh"
    iter = 20000
    key_len = 16
    OpenSSL::PKCS5.pbkdf2_hmac_sha1(pass, salt, iter, key_len)
  end
end

.request_api_key(project_name:, user:, payout_account:) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 38

def request_api_key(project_name:, user:, payout_account:)
  response = make_api_call(project_name, user, )

  new_api_key = response.data["apikey"]
  contract_id = response.data["contract_id"]
   = response.data["payin_account"]

  encryption = encrypt(new_api_key, project_name)

  self.new(
    ciphertext: encryption[:ciphertext],
    iv: encryption[:iv],
    project_name: project_name,
    mac: encryption[:mac],
    contract_id: contract_id,
    payin_account: 
  )
end

Instance Method Details

#keyObject



20
21
22
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 20

def key
  decrypt
end