_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

API Key Management — správa API klíčů

09. 01. 2025 1 min read intermediate

API klíče jsou nejjednodušší forma autentizace — a nejčastěji kompromitovaná. Klíče v GitHubu, ve frontendu, bez expirace.

Generování

import secrets, hashlib def generate_api_key(prefix=”sk”): raw = secrets.token_urlsafe(32) full = f”{prefix}_{raw}” hash = hashlib.sha256(full.encode()).hexdigest() return full, hash # full → uživateli JEDNOU, hash → do DB

Ukládání

❌ API_KEY = “sk_live_abc123” # V kódu!

✅ os.environ[‘STRIPE_API_KEY’]

✅ Secret manager (Vault, AWS SM, Azure KV)

Best Practices

  1. Hashujte klíče v DB (SHA-256)
  2. Prefix pro rozlišení (sk_live_, sk_test_)
  3. Expirace a rotace
  4. Scope — minimální oprávnění per klíč
  5. Pre-commit hooks (gitleaks, truffleHog)

Key Takeaway

API klíče hashujte, rotujte, omezujte scope. Nikdy necommitujte do Gitu.

securityapiklíčemanagement
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.