Skip to Content

When is HS256 right, when do you need RS256?

Category: Security & Compliance

Answer

HS256 (HMAC, shared secret) is fine for monolith services where the same code signs AND verifies. RS256 (asymmetric, public key verifies, private key signs) is required when multiple services verify tokens issued by a single auth service — only the auth service holds the signing key. For multi-service auth, RS256 avoids sharing secrets.

Concrete examples from the fca project context

Example 1

Single FastAPI service: HS256 with secret in env, simple and fast.

Example 2

Multi-service (auth + API + UI): RS256, auth service signs with private key, others verify with public key.

Example 3

JWT_ALG settings field makes migration a config swap, not a code rewrite.

Data flow / flow chart

Issuer (private key) -> sign -> JWT -> Verifier (public key) -> accept
  Symmetric (HS256) if both are the same service; asymmetric (RS256) otherwise

Takeaway

HS256 for monolith, RS256 once a second service needs to verify.