Argon2Sharp 3.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Argon2Sharp --version 3.5.0
                    
NuGet\Install-Package Argon2Sharp -Version 3.5.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Argon2Sharp" Version="3.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Argon2Sharp" Version="3.5.0" />
                    
Directory.Packages.props
<PackageReference Include="Argon2Sharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Argon2Sharp --version 3.5.0
                    
#r "nuget: Argon2Sharp, 3.5.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Argon2Sharp@3.5.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Argon2Sharp&version=3.5.0
                    
Install as a Cake Addin
#tool nuget:?package=Argon2Sharp&version=3.5.0
                    
Install as a Cake Tool

<div align="center">

🔐 Argon2Sharp

Pure C# Implementation of Argon2 Password Hashing Algorithm

.NET 8.0 .NET 9.0 .NET 10.0 Build Status Tests License RFC 9106

A modern, high-performance, pure C# implementation of the Argon2 password hashing algorithm following RFC 9106 specification.

Features • Installation • Quick Start • API Reference • Benchmarks

</div>


✨ Features

  • Pure C# - No native dependencies, runs anywhere .NET runs
  • RFC 9106 compliant - Argon2d, Argon2i, Argon2id support
  • Immutable parameters - Thread-safe Argon2Parameters sealed record
  • Builder pattern - Fluent API for parameter construction
  • Span-based API - Zero-allocation hot paths with ReadOnlySpan<byte>
  • PHC string format - Standard format for password hash storage
  • SIMD optimized - AVX2 hardware acceleration for block operations
  • Parallel lane processing - Multi-threaded hashing for high-security workloads
  • Secure memory cleanup - CryptographicOperations.ZeroMemory() for sensitive data
  • Multi-target - .NET 8.0, 9.0, 10.0 support

📦 Installation

git clone https://github.com/Paol0B/Argon2id.git
cd Argon2id
dotnet build -c Release

🚀 Quick Start

using Argon2Sharp;

// Hash password to PHC format string
string phcHash = Argon2PhcFormat.HashToPhcStringWithAutoSalt("MyPassword123");
// Output: $argon2id$v=19$m=19456,t=2,p=1$...salt...$...hash...

// Verify password
var (isValid, parameters) = Argon2PhcFormat.VerifyPhcString("MyPassword123", phcHash);

Basic Hashing

using Argon2Sharp;

// Hash with auto-generated salt
var (hash, salt) = Argon2.HashPasswordWithSalt("MyPassword123");

// Verify with same parameters
var parameters = Argon2Parameters.CreateDefault() with { Salt = salt };
var argon2 = new Argon2(parameters);
bool isValid = argon2.Verify("MyPassword123", hash.AsSpan());

Builder Pattern

using Argon2Sharp;

var parameters = Argon2Parameters.CreateBuilder()
    .WithMemorySizeKB(65536)    // 64 MB
    .WithIterations(4)
    .WithParallelism(4)
    .WithRandomSalt()
    .Build();

var argon2 = new Argon2(parameters);
byte[] hash = argon2.Hash("MyPassword123");

📖 API Reference

Argon2Parameters

Immutable record for hash configuration.

// Factory methods
Argon2Parameters.CreateDefault()       // 19 MB, 2 iterations, 1 parallelism
Argon2Parameters.CreateHighSecurity()  // 64 MB, 4 iterations, 4 parallelism
Argon2Parameters.CreateForTesting()    // 32 KB, 3 iterations (fast, not secure)

// Builder pattern
Argon2Parameters.CreateBuilder()
    .WithType(Argon2Type.Argon2id)
    .WithMemorySizeKB(65536)
    .WithIterations(4)
    .WithParallelism(4)
    .WithHashLength(32)
    .WithSalt(salt)           // Explicit salt
    .WithRandomSalt(16)       // Auto-generate salt
    .WithSecret(key)          // Optional secret key
    .WithAssociatedData(ctx)  // Optional associated data
    .Build();

// Modify with 'with' expression
var modified = parameters with { Salt = newSalt };

Argon2 Class

Main hashing class.

var argon2 = new Argon2(parameters);

// Hash methods
byte[] hash = argon2.Hash("password");
byte[] hash = argon2.Hash(passwordSpan);

// Verify methods
bool valid = argon2.Verify("password", hashSpan);
bool valid = argon2.Verify(passwordSpan, hashSpan);

// Static methods
var (hash, salt) = Argon2.HashPasswordWithSalt("password");
byte[] salt = Argon2.GenerateSalt(16);

Argon2PhcFormat

PHC string format utilities.

// Hash to PHC string
string phc = Argon2PhcFormat.HashToPhcStringWithAutoSalt("password");
string phc = Argon2PhcFormat.HashToPhcString("password", parameters);

// Verify from PHC string
var (isValid, params) = Argon2PhcFormat.VerifyPhcString("password", phcHash);

// Encode/decode
string phc = Argon2PhcFormat.Encode(hash, parameters);
bool ok = Argon2PhcFormat.TryDecode(phc, out hash, out parameters);

Algorithm Types

Type Use Case
Argon2id Recommended - Hybrid, resistant to GPU and side-channel attacks
Argon2i Side-channel sensitive environments
Argon2d Maximum GPU resistance (cryptocurrency, KDF)

Parameter Constraints

Parameter Minimum Recommended
Memory Size 8 KB ≥ 19 MB
Iterations 1 ≥ 2
Parallelism 1 1-4
Hash Length 4 bytes 32 bytes
Salt Length 8 bytes 16 bytes

⚡ Performance

Benchmarks on Intel Core i7-12700H (14 cores), .NET 9.0, AVX2 enabled.

Scenario Memory Iterations Parallelism Time Speedup vs v3.0
Testing 1 MB 1 1 ~53 μs 1.7x
Default 64 MB 4 4 ~15 ms 1.2x
High Security 256 MB 6 4 ~51 ms 3.0x

Optimizations

  • SIMD/AVX2 - Hardware-accelerated block operations using Vector<ulong>
  • Parallel lanes - Multi-threaded processing for p > 1
  • Loop unrolling - Fully unrolled Blake2b rounds and permutations
  • Aggressive inlining - All hot-path functions inlined
  • Hardware intrinsics - Native RotateRight instructions

🧪 Testing

dotnet test

425 unit tests covering:

  • RFC 9106 test vectors
  • Edge cases and boundary conditions
  • PHC format encoding/decoding
  • Parameter validation
  • Immutability enforcement
  • Security and stress tests
  • Interoperability tests

📄 License

MIT License - see LICENSE file.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Argon2Sharp:

Package Downloads
SPTarkov.Server.Web

Common shared library for the Single Player Tarkov projects.

SPTushonka.Server.Web

Common shared library for the Single Player Tushonka projects.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.1 12,748 1/8/2026
4.0.0 189 1/1/2026
3.5.0 760 12/1/2025
3.0.0 292 11/25/2025
2.0.0 363 11/12/2025
1.0.0 239 11/2/2025