NativeCryptoProvider

Namespace: WvdS.System.Security.Cryptography.Providers

P/Invoke-based crypto provider for server and desktop applications. Communicates directly with OpenSSL 3.6 via Platform Invocation Services.

Overview

The NativeCryptoProvider is the default provider for:

  • Blazor Server
  • ASP.NET Core
  • Desktop applications (Windows, Linux, macOS)
  • Console applications
  • Windows Services / Linux Daemons

Properties

Property Type Description
Name string "Native (P/Invoke)"
IsAvailable bool true if OpenSSL 3.6 is reachable

Initialization

using WvdS.System.Security.Cryptography.Providers;
 
// Create provider
var provider = new NativeCryptoProvider();
 
// Initialize (loads OpenSSL)
await provider.InitializeAsync();
 
// Check if available
if (provider.IsAvailable)
{
    Console.WriteLine($"Provider: {provider.Name}");
    Console.WriteLine($"OpenSSL: {provider.GetOpenSslVersion()}");
}

ML-DSA Operations

GenerateMlDsaKeyPairAsync

Generates an ML-DSA key pair.

var (publicKey, privateKey) = await provider.GenerateMlDsaKeyPairAsync("ML-DSA-65");
 
// Supported algorithms:
// - "ML-DSA-44" (NIST Level 1)
// - "ML-DSA-65" (NIST Level 3, recommended)
// - "ML-DSA-87" (NIST Level 5)

SignMlDsaAsync / VerifyMlDsaAsync

byte[] data = Encoding.UTF8.GetBytes("Important data");
byte[] signature = await provider.SignMlDsaAsync(data, privateKey);
bool isValid = await provider.VerifyMlDsaAsync(data, signature, publicKey);

ML-KEM Operations

GenerateMlKemKeyPairAsync

var (publicKey, privateKey) = await provider.GenerateMlKemKeyPairAsync("ML-KEM-768");
 
// Supported algorithms:
// - "ML-KEM-512" (NIST Level 1)
// - "ML-KEM-768" (NIST Level 3, recommended)
// - "ML-KEM-1024" (NIST Level 5)

EncapsulateAsync / DecapsulateAsync

var (sharedSecret, ciphertext) = await provider.EncapsulateAsync(recipientPublicKey);
byte[] sharedSecret = await provider.DecapsulateAsync(ciphertext, privateKey);

Method Overview

Method Parameters Return
InitializeAsync() - Task
GetOpenSslVersion() - string
GenerateMlDsaKeyPairAsync string algorithm Task<(byte[], byte[])>
SignMlDsaAsync byte[] data, byte[] privateKey Task<byte[]>
VerifyMlDsaAsync byte[] data, byte[] signature, byte[] publicKey Task<bool>
GenerateMlKemKeyPairAsync string algorithm Task<(byte[], byte[])>
EncapsulateAsync byte[] publicKey Task<(byte[], byte[])>
DecapsulateAsync byte[] ciphertext, byte[] privateKey Task<byte[]>
CreateEphemeralCertificateAsync string subject, TimeSpan validity, byte[] privateKey Task<byte[]>
SignCertificateAsync byte[] tbsCertificate, byte[] privateKey Task<byte[]>

OpenSSL Path Configuration

// Set path before InitializeAsync()
CryptoConfig.OpenSslPath = @"C:\OpenSSL\bin";
 
var provider = new NativeCryptoProvider();
await provider.InitializeAsync();

Default search paths:

Operating System Paths
Windows .\, C:\OpenSSL\bin, PATH
Linux /usr/local/lib64, /usr/lib/x86_64-linux-gnu
macOS /opt/homebrew/lib, /usr/local/lib

Security Notes

  • Requires OpenSSL 3.6.0 or higher with PQ algorithms
  • Private keys are held in process memory
  • For highest security: Explicitly clear keys with CryptographicOperations.ZeroMemory

See Also


Wolfgang van der Stille @ EMSR DATA d.o.o. - Post-Quantum Cryptography Professional

Zuletzt geändert: on 2026/01/29 at 11:16 PM