Minimal .NET library for secure password hashing using PBKDF2 (HMACSHA512) with support for salt, optional pepper, and configurable iterations.
This library was created to demonstrate secure authentication fundamentals in .NET and to provide a small, dependency-free hashing component that can be integrated into any application (e.g., Web APIs, MVC apps, background services).
- PBKDF2 (HMACSHA512) password hashing
- Secure random salt generation
- Optional pepper support (stored outside the database)
- Configurable iteration count
- Simple password verification
- Easy integration into any .NET application
dotnet add package Hasher.KenKoV1 --version 1.0.0Install-Package Hasher.KenKoV1 -Version 1.0.0using Hasher.Services;
var hashService = new HashService();
string password = "MySecurePassword123!";
string salt = hashService.GenerateSalt(16);
string pepper = "<your-secret-pepper>";
int iterations = 100_000;
string hash = hashService.GeneratePasswordHash(password, salt, pepper, iterations);
// Later for verification:
bool isValid = hashService.VerifyPassword(password, salt, pepper, iterations, hash);- Salt should be unique per user and stored in the database.
- Pepper should be stored outside the database (e.g., environment variable or secret vault).
- Iteration count should match your security and performance requirements (start around 100,000+ depending on environment).
- Never reuse the same salt across different users.
- Always use HTTPS when transmitting passwords.
- Minimal and dependency-free
- Explicit parameter control (salt, pepper, iterations)
- Clear separation between hashing and verification
- Security-first implementation approach
| Method | Description |
|---|---|
GenerateSalt(int length) |
Generates a secure random salt (Base64). |
GeneratePasswordHash(string password, string salt, string pepper, int iterations) |
Generates a PBKDF2 hash and returns it as Base64. |
VerifyPassword(string password, string salt, string pepper, int iterations, string hashToCompare) |
Recomputes the hash and compares it. |
MIT