For ECC (EC_v1), Decrypt thedatakey using AES–256 (id-aes256-GCM 2.16.840.1.101.3.4.1.46), with an initialization vector of 16 null bytes and no associated authentication data.
symmetricKey := []byte("derived_symmetric_key_32chars_xx")
ciphertext := []byte("applepay_encrypted_data")
block, _ := aes.NewCipher(symmetricKey)
aesgcm, _ := cipher.NewGCM(block)
nonce := make([]byte, aesgcm.NonceSize())
plaintext, err := aesgcm.Open(cipherText[:0], nonce, cipherText, nil)
if err != nil {
panic(err)
}
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import ciphers
...
mode = ciphers.modes.GCM(b'\0' * 16, ciphertext[-16:], 16)
decryptor = ciphers.Cipher(ciphers.algorithms.AES(symmetric_key), mode, backend=default_backend()).decryptor()
print decryptor.update(cipherdata[:-16]) + decryptor.finalize()
More context:I'm trying to decrypt ApplePay tokens. Apple requires the data to be decrypted using AES–256 GCM with an initialization vector of 16 null bytes and no authentication data (step-4 in https://developer.apple.com/library/content/documentation/PassKit/Reference/PaymentTokenJSON/PaymentTokenJSON.html)
For ECC (EC_v1), Decrypt thedatakey using AES–256 (id-aes256-GCM 2.16.840.1.101.3.4.1.46), with an initialization vector of 16 null bytes and no associated authentication data.How do I do this using the standard crypto/aes library which doesn't take initialization vector as a param?Below is my reference implementation (error checking ignored for brevity). This code fails with the error "cipher: message authentication failed".