JavaScript
Request and decrypt a card's full number and CVV with Node.js. The same decryption works for the PIN.
This guide shows how to request and decrypt sensitive card details with Node.js. 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:
fetch, which Node.js has by default from version 18.Generate the RSA key pair
Generate a 2048-bit RSA key pair in memory with the built-in Node.js crypto module. Keep the private key in scope, because you need it to decrypt the response:
Encode the public key
Export the public key as PEM (SubjectPublicKeyInfo), then Base64-encode the entire PEM string. This is the value to send in the X-Client-Public-Key header:
Do not send only the modulus (nfrom a JSON Web Key), the raw DER bytes, or the PEM string without Base64-encoding it. 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 payload contains the encrypted_key, nonce, and ciphertext fields that you need to decrypt the card details. The next steps use the in-memory privateKey that you generated in 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 |
Decode the Base64 values
Convert all three Base64-encoded values from the API response into buffers:
Decrypt the AES key
Use your RSA private key to decrypt the AES key. The decryption uses RSA-OAEP padding with SHA-256. The key option accepts a crypto.KeyObject (such as the in-memory privateKey from the first step) or a PEM-encoded string:
Separate the authentication tag
The last 16 bytes of the ciphertext are the GCM authentication tag. Separate the tag from the encrypted data:
Decrypt the card details
Create an AES-256-GCM decipher, set the authentication tag, and decrypt the card details:
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. It then logs the decrypted card details:
If you already have the encrypted payload and only need to decrypt it, call crypto.privateDecrypt and crypto.createDecipheriv as in Decrypt the AES key and Decrypt the card details. Pass your PEM string in the key option.