Class: ApplePay::PaymentToken::EncryptedData
- Inherits:
-
Object
- Object
- ApplePay::PaymentToken::EncryptedData
- Defined in:
- lib/apple_pay/payment_token/encrypted_data.rb
Defined Under Namespace
Classes: DecryptionFailed
Constant Summary collapse
- MERCHANT_ID_OID =
'1.2.840.113635.100.6.32'
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#decrypt!(client_cert, private_key, ephemeral_public_key_or_wrapped_key) ⇒ Object
NOTE: Payment Processing Certificate.
-
#initialize(encoded_data) ⇒ EncryptedData
constructor
A new instance of EncryptedData.
Constructor Details
#initialize(encoded_data) ⇒ EncryptedData
Returns a new instance of EncryptedData.
10 11 12 |
# File 'lib/apple_pay/payment_token/encrypted_data.rb', line 10 def initialize(encoded_data) self.data = Base64.decode64 encoded_data end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/apple_pay/payment_token/encrypted_data.rb', line 8 def data @data end |
Instance Method Details
#decrypt!(client_cert, private_key, ephemeral_public_key_or_wrapped_key) ⇒ Object
NOTE: Payment Processing Certificate
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/apple_pay/payment_token/encrypted_data.rb', line 14 def decrypt!(client_cert, private_key, ephemeral_public_key_or_wrapped_key) # NOTE: Payment Processing Certificate merchant_id = merchant_id_in client_cert shared_secret = shared_secret_derived_from private_key, ephemeral_public_key_or_wrapped_key symmetric_key = symmetric_key_derived_from merchant_id, shared_secret cipher = OpenSSL::Cipher.new('aes-256-gcm') cipher.decrypt cipher.iv_len = 16 # NOTE: require ruby 2.4.0+ & openssl gem v2.0.0+ cipher.key = symmetric_key cipher.auth_tag = data[-16..-1] cipher.update(data[0..-17]) + cipher.final end |