toolqik

03 · Generators

API Key Generator

Prefixed, high-entropy API keys in base62, hex or base64url.

Runs in your browser
Encoding
Entropy
API keys
    Tip: store only a SHA-256 hash of each key in your database, and compare hashes on each request. A readable prefix like sk_live_ lets secret scanners and humans recognise leaked keys.

    About this tool

    An API key is a long random secret that identifies an app or user calling your API. It must be impossible to guess, easy to recognise when it leaks, and never stored in plain text. This API key generator creates keys with the amount of randomness you choose, from your browser’s cryptographically secure random number generator, with an optional prefix in the style of Stripe or GitHub keys.

    How to use it

    1. Type a prefix that says what the key is, such as sk_live_ or myapp_test_, or leave it empty.
    2. Choose the encoding and entropy. 256-bit base62 is a strong, compact default.
    3. Generate as many as you need (up to 20), then copy or download them. Keys are created in your browser and never sent anywhere.

    Anatomy of a good API key

    A well-designed key such as acme_live_7Hq2LyjWDa9rjtT1zdp7dcK4 has two parts:

    • A readable prefix that names the product, the key type and the environment. Humans can tell a live key from a test key at a glance, your logs can be searched for it, and secret scanners (including GitHub’s push protection) can spot it when someone commits it by mistake.
    • A random body with at least 128 bits of entropy, encoded without characters that need escaping. Base62 (letters and digits) is ideal: safe in URLs, headers and JSON, and selectable with a double-click.

    Real-world API key prefixes

    ServicePrefixMeaning
    Stripesk_live_, sk_test_, pk_live_Secret or publishable key, live or test mode
    GitHubghp_, github_pat_, gho_Classic personal token, fine-grained token, OAuth token
    Slackxoxb-, xoxp-Bot token, user token
    Google CloudAIzaAPI key
    AWSAKIAAccess key ID (paired with a separate secret key)

    Key length by encoding

    Entropybase62base64urlhex
    128 bits22 characters22 characters32 characters
    256 bits43 characters43 characters64 characters
    512 bits86 characters86 characters128 characters

    All three encodings are equally secure for the same entropy; only the length and the character set differ.

    How to store and verify API keys

    • Show the key once. Display it to the user when it’s created, then store only a SHA-256 hash. If your database leaks, the keys don’t.
    • SHA-256 is the right hash here. Unlike passwords, random 256-bit keys can’t be brute-forced, so a slow hash like bcrypt only adds latency to every API call.
    • Look keys up by their hash with a unique index. Store the prefix and the last 4 characters separately so users can tell their keys apart in your dashboard.
    • Support rotation and revocation: let users create a new key before deleting the old one, record when each key was last used, and allow scopes and expiry dates.
    • Never put secret keys in front-end code or mobile apps. Anything shipped to a browser or phone can be extracted.
    const crypto = require('node:crypto');
    
    const sha256 = (s) => crypto.createHash('sha256').update(s).digest('hex');
    
    // Create: show the key to the user ONCE, store only its hash
    function createApiKey() {
      const key = 'sk_live_' + crypto.randomBytes(32).toString('base64url');
      return { key, hash: sha256(key), last4: key.slice(-4) };
    }
    
    // Verify: hash what the client sent and look it up (unique index on hash)
    async function findKey(presented) {
      return db.apiKeys.findOne({ hash: sha256(presented), revokedAt: null });
    }

    Hash a key by hand with the SHA-256 generator. For signing webhooks or JWTs rather than authenticating callers, use the webhook secret or JWT secret generators.

    FAQ

    How do I generate an API key?

    Use a cryptographically secure random generator to create at least 128 bits (ideally 256) of random data, encode it as base62, hex or base64url, and add a prefix that identifies your product and environment. This page does all of that in one click.

    What is the best format for an API key?

    A readable prefix such as myapp_live_ followed by 32–43 random base62 characters. It is URL-safe, easy to copy, and easy for secret scanners to recognise if it leaks.

    How many bits of entropy does an API key need?

    128 bits is the practical minimum; 256 bits is a comfortable default. Beyond that, length adds little security but makes keys harder to handle.

    Should I store API keys in plain text?

    No. Store a hash (SHA-256 is fine for high-entropy random keys) and show the full key to the user only once, at creation time.

    Base62, hex or base64url?

    All three are equally secure for the same entropy. Base62 is the most compact without special characters, and hex is the easiest to type and compare.

    esc
    ↑↓ navigate↵ open