Class: SecupayRuby::ApiKey::SubKey
- Inherits:
-
Object
- Object
- SecupayRuby::ApiKey::SubKey
- Defined in:
- lib/secupay_ruby/api_key/sub_key.rb
Instance Attribute Summary collapse
-
#ciphertext ⇒ Object
readonly
Returns the value of attribute ciphertext.
-
#contract_id ⇒ Object
Returns the value of attribute contract_id.
-
#iv ⇒ Object
readonly
Returns the value of attribute iv.
-
#mac ⇒ Object
readonly
Returns the value of attribute mac.
-
#payin_account ⇒ Object
Returns the value of attribute payin_account.
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
Class Method Summary collapse
- .cipher ⇒ Object
- .generate_secure_key ⇒ Object
- .request_api_key(project_name:, user:, payout_account:) ⇒ Object
Instance Method Summary collapse
-
#initialize(ciphertext:, iv:, mac:, project_name:, contract_id:, payin_account: {}) ⇒ SubKey
constructor
Changing “iv”, “mac” or “project_name” will cause a bad decrypt when getting key!.
- #key ⇒ Object
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
#ciphertext ⇒ Object (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_id ⇒ Object
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 |
#iv ⇒ Object (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 |
#mac ⇒ Object (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_account ⇒ Object
Returns the value of attribute payin_account.
8 9 10 |
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 8 def end |
#project_name ⇒ Object (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
.cipher ⇒ Object
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_key ⇒ Object
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, payout_account) 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
#key ⇒ Object
20 21 22 |
# File 'lib/secupay_ruby/api_key/sub_key.rb', line 20 def key decrypt end |