Ed25519 to Curve25519 keys conversion

Ed25519 keys can be converted to Curve25519 keys, so that the same key pair can be used both for authenticated encryption PublicKeyBox and for signatures PublicKeyAuth.

Example


//Create a new key pair based on a random seed
var keys = PublicKeyAuth.GenerateKeyPair();

var ed25519Pk = keys.PublicKey;
var ed25519SkPk = keys.PrivateKey;

//Convert it
var curve25519Pk = PublicKeyAuth.ConvertEd25519PublicKeyToCurve25519PublicKey(ed25519Pk);
var curve25519Sk = PublicKeyAuth.ConvertEd25519SecretKeyToCurve25519SecretKey(ed25519SkPk);

Usage

Convert PublicKey

public static byte[] ConvertEd25519PublicKeyToCurve25519PublicKey(byte[] ed25519PublicKey)

This is the .NET equivalent of crypto_sign_ed25519_pk_to_curve25519.

Namespace: Sodium.PublicKeyAuth

The ConvertEd25519PublicKeyToCurve25519PublicKey() function converts an Ed25519 public key ed25519PublicKey to a Curve25519 public key and returns it as a byte array.

The key must be 32 bytes, otherwise the function throws a KeyOutOfRangeException.

The function returns a byte array on success, or throws an CryptographicException() on failure.

Convert SecretKey

 public static byte[] ConvertEd25519SecretKeyToCurve25519SecretKey(byte[] ed25519SecretKey)

This is the .NET equivalent of crypto_sign_ed25519_sk_to_curve25519.

Namespace: Sodium.PublicKeyAuth

The ConvertEd25519SecretKeyToCurve25519SecretKey() function converts an Ed25519 secret key ed25519SecretKey to a Curve25519 secret key and returns it as a byte array.

The key must be 32 bytes, otherwise the function throws a KeyOutOfRangeException.

The function returns a byte array on success, or throws an CryptographicException() on failure.