Skip to content

Latest commit

Β 

History

History
105 lines (77 loc) Β· 2.83 KB

File metadata and controls

105 lines (77 loc) Β· 2.83 KB

πŸ” Google Pay Payload Decryption & Formatter

This project provides tools for working with Google Pay encrypted payloads:

  • Decrypt payloads using Google's ECv2 protocol in Java.
  • Format payloads into Omise-style JSON using a Go helper.
  • Extract the base64 public key derived from your Google Pay private key.

πŸ“ Project Structure

.
β”œβ”€β”€ cmd/
β”‚   └── google_pay_public_key_helper/
β”‚       └── main.go                # Go helper to derive the public key from GOOGLE_PAY_PRIVATE_KEY
β”œβ”€β”€ internal/
β”‚   └── googlepay/
β”‚       β”œβ”€β”€ keyutil.go             # Shared EC key conversion utilities
β”‚       └── keyutil_test.go        # Tests for public-key derivation
β”œβ”€β”€ src/
β”‚   └── main/
β”‚       └── java/
β”‚           └── DecryptApp.java    # Java decryption entrypoint
β”œβ”€β”€ google_pay_json_helper.go      # Go helper to format Google Pay JSON payload
β”œβ”€β”€ go.mod                         # Go module definition file
β”œβ”€β”€ go.sum                         # Go dependency checksum file
β”œβ”€β”€ pom.xml                        # Maven build configuration file
β”œβ”€β”€ Makefile                       # Makefile to simplify build and run commands
β”œβ”€β”€ .env                           # Environment variables for configuration
└── README.md                      # Project overview and usage instructions

πŸ”§ Setup

1. Install dependencies

# Java / Maven
brew install maven   # or use apt/choco depending on your OS

# Go (if not installed)
brew install go

2. Environment Variables

Create a .env file in the project root with the following:

GOOGLE_PAY_ENV=test # or prod
GOOGLE_PAY_MERCHANT_ID=gateway:your_gateway_name
GOOGLE_PAY_PRIVATE_KEY=YOUR_PKCS8_BASE64_KEY
GOOGLE_PAY_PAYLOAD={"signature":"...","protocolVersion":"ECv2",...}

GOOGLE_PAY_PRIVATE_KEY is expected to be a base64-encoded PKCS#8 EC private key. The Go helpers derive the matching public key from this value automatically in Google Pay's uncompressed point format.


▢️ Usage

Decrypt payload (Java)

make decrypt

Format payload as Omise JSON

make payload

Output:

{
  "public_key": "<base64 uncompressed EC public key derived from GOOGLE_PAY_PRIVATE_KEY>",
  "data": "{...original payload JSON...}"
}

Extract the derived public key

make public-key

Output:

MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE...

πŸ›  Development Notes

  • Decryption uses Tink (Google's crypto library).
  • The Go helpers expect GOOGLE_PAY_PRIVATE_KEY to be a base64-encoded PKCS#8 EC private key.
  • The Go formatter pulls the payload from the GOOGLE_PAY_PAYLOAD env variable and derives public_key from the private key in uncompressed point format.