An elliptic curve offering 128 bits of security and designed for use with the elliptic curve Diffie–Hellman (ECDH) key agreement scheme. It is one of the fastest ECC curves and is not covered by any known patents.
$ dotnet add package Curve25519.NetCoreCurve25519.NetCore is a .NET implementation of Curve25519 (X25519) focused on elliptic-curve Diffie-Hellman (ECDH) key agreement.
It provides a compact API for:
The library targets modern .NET and follows RFC 7748 guidance by rejecting all-zero shared secrets.
SecureRandom.NetCore (v2.x) for random private key generation.dotnet add package Curve25519.NetCore
Install-Package Curve25519.NetCore
using System;
using System.Linq;
using Curve25519.NetCore;
var curve25519 = new Curve25519();
// Alice key pair
var alicePrivate = curve25519.CreateRandomPrivateKey();
var alicePublic = curve25519.GetPublicKey(alicePrivate);
// Bob key pair
var bobPrivate = curve25519.CreateRandomPrivateKey();
var bobPublic = curve25519.GetPublicKey(bobPrivate);
// Shared secret derivation
var aliceShared = curve25519.GetSharedSecret(alicePrivate, bobPublic);
var bobShared = curve25519.GetSharedSecret(bobPrivate, alicePublic);
var equal = aliceShared.SequenceEqual(bobShared);
Console.WriteLine($"Shared secrets match: {equal}");
GetSharedSecret(...)returns raw shared secret bytes. In protocol design, derive final session keys from this output using an appropriate KDF.
Curve25519public const int KeySize = 32;
byte[] CreateRandomPrivateKey()
byte[] ClampPrivateKey(byte[] rawKey)
void ClampPrivateKeyInline(byte[] key)
CreateRandomPrivateKey() generates 32 random bytes and clamps them before returning.byte[] GetPublicKey(byte[] privateKey)
byte[] GetSigningKey(byte[] privateKey)
byte[] GetSharedSecret(byte[] privateKey, byte[] peerPublicKey)
GetPublicKey(...) derives a 32-byte public key.GetSharedSecret(...) performs X25519 with length validation.CryptographicException.The test project includes RFC 7748 vector validation and agreement checks, covering:
Run the test suite:
dotnet test Curve25519.NetCore.sln
Treat private keys as sensitive
Always validate key sizes at boundaries
Use a KDF on shared secrets
Reject invalid agreement outputs
Avoid sharing mutable key arrays across threads
dotnet build Curve25519.NetCore.sln
dotnet test Curve25519.NetCore.sln
MIT. See LICENSE.