toolqik

30 · Generators

Secure Token Generator

Cryptographically secure random tokens in hex, Base64URL, Base62 or Base32.

Runs in your browser
Strength
Encoding
Tokens

    About this tool

    Password-reset links, email verification, invitations, unsubscribe links, magic sign-in links and session IDs all depend on one thing: a token nobody can guess. This generator creates them from your browser’s cryptographically secure random number generator, in the encoding your system expects.

    Choosing an encoding

    Encoding256-bit lengthGood for
    Base64URL43 charactersURLs, cookies and headers: the most compact URL-safe choice
    Hex64 charactersLogs, databases and anything case-insensitive
    Base6243 charactersLetters and digits only; safe to double-click and select
    Base3252 charactersCase-insensitive systems and codes people type
    Base6444 charactersConfig files; contains + and /, so not for URLs

    Using tokens safely

    • 128 bits is the minimum for anything that grants access; 256 bits costs nothing extra.
    • Store a hash, not the token. Save SHA-256(token) in your database and compare hashes, so a database leak doesn’t leak working links.
    • Expire and use once. Reset and verification tokens should expire within an hour or so and be deleted after use.
    • Prefixes help. A prefix such as reset_ identifies the token’s purpose in logs and helps secret scanners spot leaks.

    Secure tokens in code

    import { randomBytes } from 'node:crypto';
    
    randomBytes(32).toString('base64url');   // 43 chars, 256 bits
    randomBytes(32).toString('hex');         // 64 chars

    FAQ

    How long should a secure token be?

    At least 128 bits of randomness; 256 bits is the common choice and the default here.

    Which encoding should I use for URLs?

    Base64URL: it is compact and uses only letters, digits, - and _, which need no escaping in URLs.

    Should I store tokens in my database?

    Store a SHA-256 hash of the token instead. When the user returns, hash the token they present and compare.

    Is this different from a UUID?

    A UUID v4 has 122 random bits in a fixed format. A secure token can have more randomness and a more compact encoding, which suits secrets better.

    esc
    ↑↓ navigate↵ open