Generate Key Pair

While our developer portal is still under development, we can still collaborate seamlessly through a simple two-step integration process.

First, please generate an RSA key pair (private and public keys) using the SHA256 with RSA signature algorithm.

Below, we have provided a JavaScript/Java example for your reference:

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.util.Base64;

public class RSAKeyPairGenerator {

    /**
     * Generate RSA key pair
     * @return An object containing the private key and public key in Base64 format
     */
    public static KeyPair genKeyPair() {
        try {
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");

            KeyPair keyPair = keyPairGenerator.generateKeyPair();
            return keyPair;

        } catch (NoSuchAlgorithmException e) {
            System.err.println("Key pair generation failed: " + e.getMessage());
            return null;
        }
    }

    public static void main(String[] args) {
        KeyPair keyPair = genKeyPair();
        if (keyPair != null) {
            PrivateKey privateKey = keyPair.getPrivate();
            PublicKey publicKey = keyPair.getPublic();

            // Encode keys to Base64
            String base64PrivateKey = Base64.getEncoder().encodeToString(privateKey.getEncoded());
            String base64PublicKey = Base64.getEncoder().encodeToString(publicKey.getEncoded());

            System.out.println("Private Key: " + base64PrivateKey);
            System.out.println("Public Key: " + base64PublicKey);
        }
    }
}
import { generateKeyPairSync } from 'crypto';

/**
 * Generate RSA key pair
 * @returns {Object|null} - An object containing the private key and public key in Base64 format
 */
function genKeyPair() {
    try {
        // Generate RSA key pair
        const { publicKey, privateKey } = generateKeyPairSync('rsa', {
            modulusLength: 2048, // Key size (not a must)
            publicKeyEncoding: {
                type: 'spki', // Standard Public Key Info
                format: 'pem' // PEM encoding
            },
            privateKeyEncoding: {
                type: 'pkcs8', // Private Key Info
                format: 'pem' // PEM encoding
            }
        });

        return {
            privateKey: privateKey, //PEM encoding private key
            publicKey: publicKey //PEM encoding public key
        };
    } catch (error) {
        console.error('Key pair generation failed:', error);
        return null;
    }
}

// Check your key pairs
const keys = genKeyPair();
if (keys) {
    console.log('PEM Encoded Private Key:', keys.privateKey);
    console.log('PEM Encoded Public Key:', keys.publicKey);
} else {
    console.log('Failed to generate keys.');
}

Once you have successfully generated the key pair, please share the public key with us. We will then register it in our database to complete the integration process.

However, The keys you generate are only for usage in the production environment. If you are planning to do it in sandbox environment first, please reach out to our team so we can get your API keys in staging environment.