This library only performs the key generation and key validation functions that your service requires. It provides interfaces for you to integrate with key generation systems, database storage systems, and authentication validation systems. Support for multiple key algorithms means you can update your key generation logic as security best practices evolve, while ensuring that old keys will continue to work.
$ dotnet add package ApiKeyGeneratorA DotNet library for generating and validating API keys. Although there are lots of libraries out there that help you implement API key logic using middleware, this library attempts to isolate exactly the code that does API key generation and validation using relatively safe practices.
The goal of this library is to strike the right balance between usability and reliability.
This library implements encryption of API keys as follows:
The library is intended to support future generations of algorithms while still being compatible with previously generated API keys.
For usability, this library works on a few basic principles:
<prefix><key ID>_<client secret><suffix>.The following articles are relevant to this library:
These performance statistics were measured on my laptop, a Dell I7-12700H. Benchmarks measure the length of time taken to do 1,000 iterations of Generate or Validate.
| Method | HashType | Mean | Error | StdDev |
|---|---|---|---|---|
| Generate | SHA256 | 2.659 ms | 0.0269 ms | 0.0239 ms |
| Validate | SHA256 | 1.214 ms | 0.0091 ms | 0.0085 ms |
| Generate | SHA512 | 3.321 ms | 0.0217 ms | 0.0203 ms |
| Validate | SHA512 | 1.821 ms | 0.0078 ms | 0.0061 ms |
| Generate | BCrypt | 12,097.053 ms | 32.9440 ms | 30.8158 ms |
| Validate | BCrypt | 12,183.813 ms | 39.5346 ms | 36.9807 ms |
| Generate | PBKDF2100K | 9,105.861 ms | 32.3737 ms | 30.2824 ms |
| Validate | PBKDF2100K | 9,153.661 ms | 51.2219 ms | 47.9130 ms |