# Generate a key pair and register a public key

Executive summary
**API users and custom clients need a cryptographic key pair. This one-time setup generates a key pair and registers the public key with the platform.**

- Generate a signing key pair using a cryptographically secure method (P-256, secp256k1, or Ed25519).
- Keep your private key secret. Share only the public key with your administrator.
- Your public key is registered via governance intent (or genesis block for initial users).
- Production keys should be generated and stored in a secure KMS, not manually.


Why this matters
Your key pair is your API identity on the platform. The private key proves you authorized every action you take — losing it means losing access, and exposing it means someone else can act as you. There is no "forgot password" recovery — key management is the user's responsibility.

**For architects and operators**: Establish key generation procedures and secure storage guidance for your users. Consider mandating hardware security keys (YubiKey) or the mobile app's secure enclave for production users rather than software-based key storage.

This guide is for API users and custom clients that need to register after the platform is running. UI users normally create a profile and store key material with the **Ripple Custody: Auth & Sign** app. Genesis users are pre-configured during platform initialization — see [Genesis](/pt-br/products/custody/governance/genesis).

## Prerequisites

Before you begin, ensure you have:

- Access to a cryptographically secure environment for key generation
- Contact information for your user administrator
- Knowledge of which key type your environment requires (ask your administrator if unsure)


## Supported key types

Ripple Custody (Vault) supports three types of cryptographic keys:

| Key type | Curve | Common use | When to choose |
|  --- | --- | --- | --- |
| **P-256 (secp256r1)** | NIST P-256 | General purpose, widely supported | Default choice for most deployments |
| **secp256k1** | Koblitz curve | Bitcoin, Ethereum ecosystems | When integrating with Bitcoin/Ethereum infrastructure |
| **Ed25519** | Edwards curve | High performance, modern systems | When performance is critical |


All keys must be in **DER format with Base64 encoding** (without PEM headers/footers).

Ask your administrator which key type is required for your environment before generating keys. Using the wrong key type will cause authentication failures.

## Step 1: Generate a key pair

Generate a key pair using a cryptographically secure method. The private key must be kept secret; the public key will be shared with your administrator.

**Production environments**: Always generate and store production keys using a cryptographically secure key management system (KMS). The OpenSSL examples below are for testing and development only.

### OpenSSL examples (non-production)

P-256 (secp256r1)
```sh
# Generate private key
openssl ecparam -genkey -name secp256r1 -noout -out privateKey.pem

# Export public key in DER format with Base64 encoding
openssl ec -in privateKey.pem -pubout -outform DER | openssl base64 -A -out publicKey.pem
```

secp256k1
```sh
# Generate private key
openssl ecparam -genkey -name secp256k1 -noout -out privateKey.pem

# Export public key in DER format with Base64 encoding
openssl ec -in privateKey.pem -pubout -outform DER | openssl base64 -A -out publicKey.pem
```

Ed25519
```sh
# Generate private key
openssl genpkey -algorithm Ed25519 -out privateKey.pem

# Export public key in DER format with Base64 encoding
openssl pkey -in privateKey.pem -pubout -outform DER | openssl base64 -A -out publicKey.pem
```

### SDK examples (non-production)

If you use a Ripple Custody (Vault) SDK, you can generate the key pair with it instead of OpenSSL. The SDKs support the same three key types. They return the private key in PKCS#8 PEM format (`-----BEGIN PRIVATE KEY-----`). They return the public key as Base64-encoded DER, which is the format your administrator registers. For SDK installation, see [Integrate via SDK](/pt-br/products/custody/get-started/integrate-via-sdk).

The TypeScript and Python SDKs include a `ripple-custody keygen` command that writes the private key to a file with `0600` permissions and prints the public key. The Java SDK has no command-line tool, so use its `Keys` class instead. The following examples generate a key pair with each SDK:

TypeScript
```sh
# --curve: P-256 (default), secp256k1, or Ed25519
npx ripple-custody keygen --curve P-256 --out privateKey.pem
```

Or generate the key pair in code:

```typescript
import { generateSigningKeypair } from '@ripple/ripple-custody-client-lib-typescript';

// 'P-256' (default), 'secp256k1', or 'Ed25519'
const { privateKeyPem, publicKeyBase64Der } = generateSigningKeypair('P-256');
// Store privateKeyPem securely. Send publicKeyBase64Der to your administrator.
```

Java
```java
import com.ripple.custody.Keys;

// SECP256R1 (P-256, the default), SECP256K1, or ED25519
Keys.SigningKeypair keypair = Keys.generateSigningKeypair(Keys.KeyType.SECP256R1);
String privateKeyPem = keypair.getPrivateKeyPem();           // Store securely
String publicKeyBase64Der = keypair.getPublicKeyBase64Der(); // Send to your administrator
```

Python
```sh
# --key-type: Secp256r1 (P-256, default), Secp256k1, or Ed25519
ripple-custody keygen --key-type Secp256r1 --out privateKey.pem
```

The command refuses to overwrite an existing key file unless you pass `--force`.

Or generate the key pair in code:

```python
from ripple_custody_client_lib_python import generate_signing_keypair

# "Secp256r1" (P-256, default), "Secp256k1", or "Ed25519"
private_key_pem, public_key_b64der = generate_signing_keypair("Secp256r1")
# Store private_key_pem securely. Send public_key_b64der to your administrator.
```

The SDKs never store the private key for you. To use the key with an SDK, set `RC_PRIVATE_KEY_FILE` to the private key file path.

Recent OpenSSL versions print `using curve name prime256v1 instead of secp256r1` for the P-256 command. `prime256v1` is the same curve, so you can ignore the message.

### View your keys

To view the private key (keep this secret):

```sh
cat privateKey.pem
```

Example output:

```
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIEfoycax3w8+JvkNv+L0CHmNUAHUcgCxlnOIpw/CoXzxoAoGCCqGSM49
AwEHoUQDQgAEg36xU2KQ6xLPCvZ3JXZYf5pFCagAb7WGMlYCN92zzgi737EOkDOC
MlZB0TY8CbzRHhG4RUdKuLkdRtD+OVIu2w==
-----END EC PRIVATE KEY-----
```

To view the public key (this is what you share):

```sh
cat publicKey.pem
```

Example output:

```
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEg36xU2KQ6xLPCvZ3JXZYf5pFCagAb7WGMlYCN92zzgi737EOkDOCMlZB0TY8CbzRHhG4RUdKuLkdRtD+OVIu2w==
```

## Step 2: Register with your administrator

Send your **public key** to your user administrator through a secure channel. Never share your private key.

Your administrator will:

1. Create a `v0_CreateUser` intent with your public key and a login ID. In the UI, **Create user** requires a **Single sign-on provider (SSO)** entry. For an API user that authenticates with a signed challenge, set the provider to `harmonize` and the login ID to the user name, such as `api-user@example.com`. In the API, set `loginIds` to `[{"id": "api-user@example.com", "providerId": "harmonize"}]`.
2. Submit the intent for governance approval (based on configured policies)
3. Notify you once your account is active


The following example shows a `v0_CreateUser` payload for an API user. Alongside the public key, it gives the user a login ID for the internal `harmonize` identity provider. When you request a JWT, the authentication server looks you up by your public key, and then uses this login ID to sign you in. A user without a `harmonize` login ID can't get a token with the signed challenge.

```json
"payload": {
   "id": "61aaa805-f9b8-11eb-b158-dcfb48cfb3cb",
   "alias": "api-user@example.com",
   "publicKey": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7ItVC+y2KerttcRjPLDs8QmDVz7yI7ElQA70Sz+cLcBI6041aObPvcNqps8eTYe2jhc2Kb5qgNgoACB3SqpYIA==",
   "roles": ["transaction-operator"],
   "loginIds": [
      {
         "id": "api-user@example.com",
         "providerId": "harmonize"
      }
   ],
   "lock": "Unlocked",
   "description": "API user",
   "customProperties": {},
   "type": "v0_CreateUser"
}
```

For the internal provider, the login ID is usually the same as the user's alias. In the console, your administrator enters the same details as the user's identity provider and login ID. For more information, see [Manage users and roles](/pt-br/products/custody/governance/users/manage-users-and-roles).

## Step 3: Verify your registration

After your administrator confirms your account is active, verify your registration by calling the [Get current user](/pt-br/products/custody/reference/api/openapi/users/getme) API operation.

1. Obtain a JWT token. See [Authenticate API requests](/pt-br/products/custody/identity-and-access/authentication/authenticate-api-requests) for the complete JWT flow.
2. Call the Get current user endpoint with your JWT:


```http
GET /v1/me
Authorization: Bearer <your_jwt_token>
```

1. Verify the response contains your public key, login identity, and domain memberships:


```json
{
  "publicKey": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE...",
  "domains": [
    {
      "id": "00000000-0000-0000-0000-000000000000",
      "alias": "Sample root domain",
      "userReference": {
        "id": "00000000-0000-0000-0000-000000000001",
        "alias": "user@example.com",
        "roles": ["admin"]
      }
    }
  ],
  "loginId": {
    "id": "user@example.com",
    "providerId": "harmonize"
  }
}
```

If you receive a successful response, your registration is complete.

## Troubleshooting

| Problem | Cause | Resolution |
|  --- | --- | --- |
| Key generation fails | OpenSSL not installed or outdated | Install or update OpenSSL |
| Public key rejected by administrator | Wrong key type or format | Verify key type matches environment requirements; ensure DER format with Base64 encoding |
| Registration not completing | Intent awaiting approval | Contact your administrator to check approval status |
| Cannot authenticate after registration | Account not yet active | Wait for administrator confirmation; check intent status |
| Token request returns `invalid_grant` with `Invalid user credentials`, although the account is active | The user has no login ID for the `harmonize` identity provider | Ask your administrator to update the user with a `harmonize` login ID, as shown in [Step 2](#step-2-register-with-your-administrator) |


## Next steps

Once registered, proceed to [Authenticate API requests](/pt-br/products/custody/identity-and-access/authentication/authenticate-api-requests) to learn how to obtain JWT tokens and sign intents for ongoing API usage.