API Key & Credential Security

API keys give access to value, not just data. That’s especially true in crypto-fintech systems, where a leaked key can mean irreversible loss of funds, user trust, or infrastructure control.

This guide teaches how to securely manage API keys and credentials across your stack: dev, staging, production, CI/CD, and internal tools. Whether you're a solo developer or building with a team, these practices will help you operate at production-grade from day one.


What You’ll Learn

How to manage API keys across environments

How to prevent accidental exposure

How to rotate and audit key usage

How to respond to compromise quickly

Advanced practices used by top-tier teams

How to log and trace transactions from API to user


1.

Never hardcode keys

Avoid hardcoding credentials into your source code — even in private repos.

Use .env, system-level secrets, or vault systems (see below) and keep them out of Git.

2.

Separate Sandbox and Production Keys

Each environment should use different API credentials.

Note

BITNOB_SANDBOX_API_KEY

BITNOB_PRODUCTION_API_KEY

3.

Keep API Keys Out of the Frontend

API keys must only live on your server or secure backend functions. Never expose them in:

Web apps (browser dev tools)

Mobile apps (decompiled APKs/IPAs)

Client-side JavaScript

Instead

Route all requests through your secure backend. Your frontend talks to your backend — not Bitnob directly.

api-key-illustration
4.

Rotate Keys Regularly

Keys should be rotated at least every 60–90 days, and immediately if:

An engineer leaves your team

A staging credential is accidentally exposed

You onboard new partners or contractors

Where possible, enable overlapping keys during rotation to avoid downtime:

Add new key (Key B)

Deploy with Key B

Remove old key (Key A)

5.

Use a Secret Manager in Production

Don’t use .env files in production. Use a vault system like:

AWS Secrets Manager

GCP Secret Manager

HashiCorp Vault

Doppler, Infisical, or 1Password Secrets Automation

These tools:

1.

Handle all messaging via webhooks

2.

Store secrets securely

3.

Provide access logs

4.

Allow key rotation and versioning


6.

Monitor for Leaks (Automatically)

Use scanning tools to detect exposed credentials early:

GitHub Advanced Security (free for public repos)

You can also write internal scripts to detect anything matching sklive or sktest.

7.

Redact Keys in Logs

Never log or expose the Authorization header or full key string in logs, dashboards, or monitoring tools.

Node.js

8.

Build for the Possibility of Compromise

Plan as if your key will leak eventually. That means:

Quick key rotation scripts

Audit logs of which service made which request

Correlating reference IDs with internal logs

Alerts for suspicious behavior (see below)

This limits your blast radius and recovery time.

9.

Audit API Usage for Anomalies

Track usage of your API key to detect abuse:

Unusual volume (e.g. airtime purchases spike)

API calls from unfamiliar IPs or geo regions

Endpoints being called that your app never uses

Start simple: alert if traffic spikes 10x, or swap requests happen outside your expected flows.

Monitor:

api.requests.total

api.requests.by-endpoint

api.requests.by-country

api.failures.by-code

If you use observability tools (Datadog, Prometheus, etc.), make this part of your standard dashboard.


10.

Use Signed Tokens Between Internal Services

If your internal services (e.g. frontend → backend, or job worker → billing service) need to authenticate requests, don’t reuse your Bitnob API key.

Instead

Generate short-lived signed tokens (e.g. JWT)

Only include required claims (user ID, action, expiry)

Verify them inside your own infrastructure


11.

Build a Proxy Layer for Your API Access (Optional)

Larger teams or API resellers often create a gateway service to manage:.

API key rotation

Logging

Rate limiting

Multi-tenant isolation

It also makes it easier to scale when you’re supporting users, partners, or white-label apps.

Note

This sits between your client apps and Bitnob, acting as a controlled and auditable layer.


12.

Support Key Expiry and Versioning (If You Issue Keys)

If you’re building your own API or multi-tenant product on top of Bitnob, implement:

Instead

Expirable keys (e.g. 90-day lifetime)

Version prefixes (v1_key_abc)

User-facing key management (generate, revoke)

This prepares your product to scale securely.

13.

Create an API Key Audit Tool

Internally, build a simple admin tool to:

List all active keys

Show last used time, IP, and endpoint

Revoke and rotate with a click

Filter by service or role

This is an incredible asset during an incident.

Summary Table

PRINCIPLEWHY IT MATTERS
Never hardcode keysPrevent leaks in source control
Use env vars and secret managersManage config safely
Rotate keys regularlyMinimize damage if leaked
Use per-env keysAvoid prod test mixups
Monitor for abuseDetect misuse early
Use signed tokens internallyDon’t reuse Bitnob keys internally
Build for compromiseRecovery should be fast and clean
Audit usage patternsStay ahead of fraud or misbehavior
Proxy or expire keysScale securely with trust boundaries

You're now equipped to treat API keys like production-grade access controls, not convenience tokens.

If you're ready, let’s move on to Webhooks & Event Handling →, where we’ll cover secure, reliable, and scalable delivery of real-time financial events.

Did you find this page useful?