owlympus/gpay-token-decrypt

Decrypt Google Pay tokens

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/owlympus/gpay-token-decrypt

dev-main 2025-12-08 23:56 UTC

This package is auto-updated.

Last update: 2025-12-13 13:29:44 UTC


README

Google Pay Token decrypt with PHP !

<?php declare(strict_types=1);

require dirname(__DIR__) . '/vendor/autoload.php';

// Cache client to store Root Signing Keys (Asked by Google for preventing HTTP request for each decryption)
$predis = new Predis\Client([
    'scheme' => 'tcp',
    'host'   => '127.0.0.1',
    'port'   => 6379,
]);

// New client with Cache and Env
$client = new \Owlympus\GpayTokenDecrypt\Client(
    new \Symfony\Component\Cache\Psr16Cache(
        new \Symfony\Component\Cache\Adapter\RedisAdapter(
            $predis
        ),
    ),
    \Owlympus\GpayTokenDecrypt\Enum\EnvironmentEnum::PRODUCTION,
);

// Load your private key
$privateKey = openssl_pkey_get_private(
    file_get_contents(__DIR__ . '/key/private.pem'), // <= your private key generated with Google documentation
);

// Your Google Pay merchant ID
$merchantId = '[YOUR MERCHANT ID]';

// Google Pay Token https://developers.google.com/pay/api/web/guides/resources/payment-data-cryptography#payment-method-token-structure
$token = '{
  "protocolVersion":"ECv2",
  "signature":"MEQCIH6Q4OwQ0jAceFEkGF0JID6sJNXxOEi4r+mA7biRxqBQAiAondqoUpU/bdsrAOpZIsrHQS9nwiiNwOrr24RyPeHA0Q\u003d\u003d",
  "intermediateSigningKey":{
    "signedKey": "{\"keyExpiration\":\"1542323393147\",\"keyValue\":\"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/1+3HBVSbdv+j7NaArdgMyoSAM43yRydzqdg1TxodSzA96Dj4Mc1EiKroxxunavVIvdxGnJeFViTzFvzFRxyCw\\u003d\\u003d\"}",
    "signatures": ["MEYCIQCO2EIi48s8VTH+ilMEpoXLFfkxAwHjfPSCVED/QDSHmQIhALLJmrUlNAY8hDQRV/y1iKZGsWpeNmIP+z+tCQHQxP0v"]
  },
  "signedMessage":"{\"tag\":\"jpGz1F1Bcoi/fCNxI9n7Qrsw7i7KHrGtTf3NrRclt+U\\u003d\",\"ephemeralPublicKey\":\"BJatyFvFPPD21l8/uLP46Ta1hsKHndf8Z+tAgk+DEPQgYTkhHy19cF3h/bXs0tWTmZtnNm+vlVrKbRU9K8+7cZs\\u003d\",\"encryptedMessage\":\"mKOoXwi8OavZ\"}"
}';

// Magic here :
$paymentData = $client->decryptToken($privateKey, $merchantId, $token);

//
var_dump($paymentData);