Skip to main content
GET
Get Public Key

Overview

This endpoint retrieves the current public key used for encrypting credit card data before sending it to Firmly’s payment endpoints. The key supports multiple formats to accommodate different encryption libraries and platforms.
The public key is rotated periodically for security. Always fetch the current key before encrypting payment data rather than caching it for extended periods.

Authentication

This endpoint requires no authentication and is publicly accessible.

Query Parameters

string
default:"JWK"
The format of the public key to returnSupported formats:
  • JWK - JSON Web Key format (default)
  • PEM - Privacy Enhanced Mail format
  • RSA - PEM using RSAPublicKey format

Response Headers

string
The key identifier (kid) - present for all formats

Response Formats

JWK Format (Default)

Returns a JSON Web Key with the following properties:
string
Key identifier/version
string
Key type (always “RSA”)
string
RSA modulus component (Base64URL encoded)
string
RSA exponent component (Base64URL encoded)
string
Key usage (always “enc” for encryption)

PEM Format

Returns the public key in PEM format as plain text:
  • Content-Type: text/plain
  • Key ID available in x-firmly-kid header
  • Standard PEM header/footer with base64 encoded key

RSA Format

Returns the public key in RSA-specific PEM format:
  • Content-Type: text/plain
  • Key ID available in x-firmly-kid header
  • Uses RSA PUBLIC KEY header/footer

Code Examples

Response Examples

JWK Format Response

PEM Format Response

RSA Format Response

Usage with Encryption Libraries

JavaScript (Web Crypto API)

Python (cryptography)

Node.js (node-jose)

Best Practices

  • Key Rotation: The public key may be cached for up to. 15 minutes. Upon invalid key error, fetch the key and retry one time. Key validation should be removed
  • Format Selection: Choose the format that works best with your encryption library
  • Error Handling: Always handle network errors when fetching the key
  • Key Validation: Verify the key ID matches between encryption and submission

Common Use Cases

  1. Credit Card Encryption: Primary use is for encrypting credit card data for payment endpoints
  2. Tokenization: Used with payment tokenization endpoints
  3. Secure Data Transmission: Any sensitive data sent to Firmly payment endpoints

Checkout Flow Integration

This endpoint is the first step in the secure payment flow:
1

Fetch Public Key

Call this endpoint to get the current encryption key
2

Encrypt Credit Card

Use the public key to encrypt card data according to your chosen format
3

Complete Order

Send encrypted card data to one of the complete-order endpoints

Complete Example Flow