Best Practices for API Secret Generation
In backend cloud infrastructure, API keys authenticate server-to-server requests without requiring interactive two-factor authentication. Consequently, API keys are prime targets for automated scanners crawling public GitHub repositories.
- Use Base62 Alphanumeric: Stripping symbols prevents URL encoding bugs and JSON escaping issues when passing keys in
Authorization: Bearer <TOKEN>headers. - Store Hashed in Database: Treat API keys like passwords on your backend: store only their SHA-256 or bcrypt hashes in your database so that a database breach does not expose active keys.