Golang
Request and decrypt a card's full number and CVV with Go. The same decryption works for the PIN.
This guide shows how to request and decrypt sensitive card details with Go. The code generates an RSA key pair in memory, Base64-encodes the public key in PEM format, and sends it in the X-Client-Public-Key header. To decrypt the response, it unwraps the Advanced Encryption Standard (AES) key with Rivest-Shamir-Adleman Optimal Asymmetric Encryption Padding (RSA-OAEP). It then decrypts the card data with Advanced Encryption Standard 256-bit Galois/Counter Mode (AES-256-GCM).
Prerequisites
Before you begin, you need:
Generate the RSA key pair
Generate a 2048-bit RSA key pair in memory with Go's crypto/rsa package. Keep the private key in scope, because you need it to decrypt the response:
Encode the public key
Marshal the public key as DER SubjectPublicKeyInfo, wrap it in a PEM block, then Base64-encode the PEM bytes. This is the value to send in the X-Client-Public-Key header:
Do not send only the modulus (Nfield of the key), the raw DER bytes, or the PEM bytes without Base64-encoding them. The header value must Base64-decode to the full PEM text, including the-----BEGIN PUBLIC KEY-----and-----END PUBLIC KEY-----markers. Gravv rejects a header that contains newlines or spaces, so you cannot send raw PEM directly.
Request the encrypted card details
Send a GET request to the View card sensitive details endpoint with the Base64-encoded public key:
The body.Data map contains the encrypted_key, nonce, and ciphertext fields that you need to decrypt the card details. The next steps use the same in-memory privateKey from Generate the RSA key pair.
Understanding the encrypted response
The View card sensitive details and the Get card PIN endpoints return three Base64-encoded values:
| Field | Description |
|---|---|
| encrypted_key | AES-256 key encrypted with your RSA public key |
| nonce | 12-byte initialization vector for AES-GCM decryption |
| ciphertext | Encrypted card details (AES-GCM ciphertext followed by the 16-byte authentication tag) |
Decode the Base64 values
Convert all three Base64-encoded values from the API response into byte slices:
Decrypt the AES key
Use your RSA private key to decrypt the AES key. The decryption uses RSA-OAEP with SHA-256:
Decrypt the card details
Create an AES-256-GCM cipher and decrypt the card details. gcm.Open checks the 16-byte authentication tag that Gravv appends to the ciphertext:
Complete end-to-end code
This code generates an RSA key pair, encodes the public key, requests sensitive card details and decrypts the response in one function. It holds the private key only in memory:
Usage example
This example calls GetCardSensitiveDetails with the API key from the GRAVV_API_KEY environment variable and a sample card ID, and prints the decrypted card details:
If you already have the encrypted payload and only need to decrypt it, parse your existing PEM private key with x509.ParsePKCS1PrivateKey (PKCS#1) or x509.ParsePKCS8PrivateKey (PKCS#8) and reuse the Decrypt the AES key and Decrypt the card details snippets.