Generate RSA Key Pair
To authenticate with our API, you need to generate an RSA key pair (public and private keys). The public key will be registered in your dashboard, while the private key will be used to sign your API requests.
The API uses RSA-2048 keys. Make sure to generate keys with a 2048-bit modulus length.
Overview
Generate the key pair
Use one of the methods below to generate your RSA key pair. You’ll get both a private key and a public key.
Extract the public key
Extract the public key from your generated key pair. The public key will be in PEM format.
Register the public key
Copy the public key and register it in your dashboard. Keep your private key secure and never share it.
Language-Specific Examples
Choose your preferred language to see how to generate RSA keys:
Shell (OpenSSL)
TypeScript/Node.js
Python
PHP
Ruby
# 1. Generate the private key
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
# 2. Extract the public key
openssl rsa -pubout -in private_key.pem -out public_key.pem
# 3. Copy the public key in the dashboard
After running these commands, you’ll have two files: private_key.pem (keep this secure) and public_key.pem (copy this to your dashboard).
const crypto = require ( 'crypto' );
// 1. Generate keys
function generateRSAKeys () {
const { privateKey , publicKey } = crypto . generateKeyPairSync ( 'rsa' , {
modulusLength: 2048 ,
publicKeyEncoding: {
type: 'spki' ,
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8' ,
format: 'pem'
}
});
console . log ( 'Private key:' , privateKey );
console . log ( 'Public key:' , publicKey );
}
// 2. Copy the public key in the dashboard
The generateRSAKeys() function returns both keys as PEM-formatted strings. Copy the public key to your dashboard.
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
# 1. Generate keys
def generate_rsa_keys ():
private_key = rsa.generate_private_key(
public_exponent = 65537 ,
key_size = 2048
)
private_pem = private_key.private_bytes(
encoding = serialization.Encoding. PEM ,
format = serialization.PrivateFormat. PKCS8 ,
encryption_algorithm = serialization.NoEncryption()
)
public_key = private_key.public_key()
public_pem = public_key.public_bytes(
encoding = serialization.Encoding. PEM ,
format = serialization.PublicFormat.SubjectPublicKeyInfo
)
return {
'private_key' : private_pem.decode( 'utf-8' ),
'public_key' : public_pem.decode( 'utf-8' )
}
# 2. Copy the public key in the dashboard
Make sure to install the cryptography package: pip install cryptography
<? php
// 1. Generate keys
function generateRSAKeys () {
$config = array (
"private_key_bits" => 2048 ,
"private_key_type" => OPENSSL_KEYTYPE_RSA ,
);
$res = openssl_pkey_new ( $config );
openssl_pkey_export ( $res , $privateKey );
$publicKeyDetails = openssl_pkey_get_details ( $res );
$publicKey = $publicKeyDetails [ "key" ];
return [
'private_key' => $privateKey ,
'public_key' => $publicKey
];
}
// 2. Copy the public key in the dashboard
Ensure the OpenSSL extension is enabled in your PHP installation.
require 'openssl'
# 1 Generate keys
def generate_rsa_keys_to_files
key = OpenSSL :: PKey :: RSA . new ( 2048 )
File . write ( 'private_key.pem' , key. to_pem )
File . write ( 'public_key.pem' , key. public_key . to_pem )
private_key = File . read ( 'private_key.pem' )
public_key = File . read ( 'public_key.pem' )
File . delete ( 'private_key.pem' )
File . delete ( 'public_key.pem' )
{
private_key: private_key,
public_key: public_key
}
end
# 2. Copy the public key in the dashboard
The example writes keys to temporary files and then reads them back. You can modify this to return keys directly if preferred.
Security Best Practices
Never share your private key. Keep it secure and never commit it to version control or expose it in client-side code.
Store your private key securely (use environment variables or secure key management services)
Use a 2048-bit key size (as shown in all examples)
Never expose your private key in logs, error messages, or public repositories
Rotate your keys periodically for enhanced security
Use different key pairs for different environments (development, staging, production)
Next Steps
After generating your RSA key pair:
Register your public key in the dashboard
Store your private key securely - you’ll need it to sign API requests
Learn about request signing - see our Request Signing guide to understand how to use your private key to authenticate API requests
Common Issues
Make sure your keys are in PEM format. PEM keys start with -----BEGIN and end with -----END.
Ensure you’re generating 2048-bit keys. Some older examples may use 1024-bit keys, which are not supported.
Public key extraction failed