Table of Contents

Class CryptoHelper.X25519EphemeralKeyPair

Namespace
FishMMO.Auth.Implementation
Assembly
FishMMO-AuthShared.dll

Disposable container for an ephemeral X25519 keypair that enforces private-key zeroization via API ownership. The private key is never exposed to callers.

public sealed class CryptoHelper.X25519EphemeralKeyPair : IDisposable
Inheritance
CryptoHelper.X25519EphemeralKeyPair
Implements
Inherited Members

Remarks

Usage pattern:

using var kp = new CryptoHelper.X25519EphemeralKeyPair();
byte[] shared = kp.DeriveSharedSecret(peerPub, transcript);
// kp.Dispose() is automatic — private key is zeroed even on exception.

Single-use: DeriveSharedSecret(byte[], byte[]) zeros the private key after the first call. Subsequent calls throw InvalidOperationException. Dispose() is idempotent and safe to call multiple times.

Constructors

X25519EphemeralKeyPair()

Generates a fresh ephemeral X25519 keypair using BouncyCastle's SecureRandom.

public X25519EphemeralKeyPair()

Properties

PublicKey

The X25519 public key (32 bytes). Not secret — safe to transmit.

public byte[] PublicKey { get; }

Property Value

byte[]

Methods

DeriveSharedSecret(byte[], byte[])

Derives a shared secret via X25519 ECDH + HKDF-SHA256. Automatically zeros the private key after derivation (single use).

public byte[] DeriveSharedSecret(byte[] peerPublicKey, byte[] handshakeTranscriptHash)

Parameters

peerPublicKey byte[]

The peer's X25519 public key (32 bytes).

handshakeTranscriptHash byte[]

Transcript hash bound into HKDF salt.

Returns

byte[]

A 32-byte HKDF-derived shared secret.

Dispose()

Zeros the private key and marks the instance as disposed.

public void Dispose()