Cryptography Utilities

Random Bytes

Generates cryptographically secure random bytes using system entropy sources. Call via MCP in Cursor/Claude Code or REST at GET /v1/crypto/random-bytes with byte count parameter. Returns base64-encoded random data suitable for keys, tokens, salts, and nonces. Uses platform-native secure random generators (urandom, CryptGenRandom).

API Endpoint

GET /v1/crypto/random-bytes

Code Examples

curl "https://tinyfn.io/v1/crypto/random-bytes" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/crypto/random-bytes', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/crypto/random-bytes',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's cryptography tools:

{
  "mcpServers": {
    "tinyfn-crypto": {
      "url": "https://tinyfn.io/mcp/crypto",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How do I generate 32 random bytes for encryption keys?

Call GET /v1/crypto/random-bytes?count=32 or use the MCP tool with count=32. Returns base64-encoded output like 'x7K9mP3qR8vL2nM...' representing 32 secure random bytes.

What's the difference between this and Math.random() for security?

This uses cryptographically secure entropy sources while Math.random() is pseudorandom and predictable. Never use Math.random() for passwords, tokens, or any security-sensitive values.

Can AI agents use this to generate secure session tokens?

Yes, MCP-enabled agents in Cursor or Windsurf can call this tool to generate unpredictable tokens. Specify sufficient entropy (16+ bytes for session IDs, 32+ for API keys).

What's the maximum number of random bytes I can request?

The API accepts reasonable limits (typically up to 1024 bytes per request) to prevent abuse. For larger needs, make multiple calls or consider if you actually need that much entropy.

Why does the output look like base64 instead of raw bytes?

Raw bytes aren't JSON-safe or readable. Base64 encoding ensures the random data survives HTTP transport and can be easily decoded in any programming language.

Try Random Bytes Now

Get your free API key and start using Random Bytes in seconds.

Get Free API Key