Class: DPay::CardEncryptor
- Inherits:
-
Object
- Object
- DPay::CardEncryptor
- Defined in:
- lib/dpay/card/card_encryptor.rb,
sig/dpay/card/card_encryptor.rbs
Instance Method Summary collapse
- #encrypt(card, transaction_id, public_key_pem, timestamp: Time.now.to_i) ⇒ String
- #load_key(public_key_pem) ⇒ OpenSSL::PKey::RSA
Instance Method Details
#encrypt(card, transaction_id, public_key_pem, timestamp: Time.now.to_i) ⇒ String
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/dpay/card/card_encryptor.rb', line 7 def encrypt(card, transaction_id, public_key_pem, timestamp: Time.now.to_i) key = load_key(public_key_pem) payload = Internal::PHP.json_encode( { "PN" => card.pan, "SC" => card.cvv, "DT" => card.expiry, "ID" => transaction_id, "TX" => }, escape_slashes: true ) [key.public_encrypt(payload, OpenSSL::PKey::RSA::PKCS1_PADDING)].pack("m0") rescue OpenSSL::PKey::PKeyError => e raise CardEncryptionError, "Card data encryption failed: #{e.}" end |
#load_key(public_key_pem) ⇒ OpenSSL::PKey::RSA
21 22 23 24 25 |
# File 'lib/dpay/card/card_encryptor.rb', line 21 def load_key(public_key_pem) OpenSSL::PKey::RSA.new(public_key_pem.to_s) rescue OpenSSL::PKey::PKeyError, ArgumentError, TypeError raise CardEncryptionError, "Invalid RSA public key" end |