Repository is archived
No commit activity in last 3 years
No release in over 3 years
Decrypt AES256GCM-encrypted data in Apple Pay Payment Tokens
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Aes256GcmDecrypt

Decrypt AES256GCM-encrypted data in Apple Pay Payment Tokens.

This library is necessary for Ruby < 2.4 (if you use the stdlib openssl rather than the openssl gem), as the OpenSSL bindings do not support setting the length of the initialisation vector (IV). Setting the IV length is necessary for decrypting Apple Pay data.

The library becomes obsolete when we start using Ruby >= 2.4.

Usage

bundle install
bundle exec rake test

irb -r base64 -I lib -r aes256gcm_decrypt

ciphertext_and_tag = Base64.decode64(File.read('spec/token_data_base64.txt'))
key = [File.read('spec/key_hex.txt').strip].pack('H*')

begin
  puts Aes256GcmDecrypt::decrypt(ciphertext_and_tag, key)
rescue Aes256GcmDecrypt::AuthenticationError => e
  # somebody is up to something
rescue Aes256GcmDecrypt::Error => e
  # super class for the possible errors; Aes256GcmDecrypt::InputError and
  # Aes256GcmDecrypt::OpenSSLError are left, i.e. either you supplied invalid
  # input or we got an unexpected error from OpenSSL
end

See also the specs.

Inspirational sources