Performance Benchmark: HMAC vs. RSA
HS256 verification is approximately 10 to 20 times faster in CPU execution than RS256 signature verification. If your API gateway handles 100,000 requests per second, HMAC provides substantial CPU efficiency gains. However, RS256 eliminates the need to distribute sensitive secrets to every consuming service.
Frequently Asked Questions
What is the algorithm confusion attack between HS256 and RS256?
An attacker takes an RS256 public key (which is public knowledge) and uses it as the secret key with HS256. If a server naively checks the token with its public key using HMAC, the signature validates. Always verify tokens with an explicit algorithm whitelist.