XDH

X25519/X448 Diffie-Hellman key agreement as defined in RFC 7748.

XDH allows two parties to establish a shared secret over an insecure channel using modern Montgomery curves. It is the recommended alternative to ECDH for new applications, offering simpler implementation and resistance to timing attacks.

val aliceKeys = provider.get(XDH).keyPairGenerator(XDH.Curve.X25519).generateKey()
val bobKeys = provider.get(XDH).keyPairGenerator(XDH.Curve.X25519).generateKey()
val sharedSecret = aliceKeys.privateKey.sharedSecretGenerator().generateSharedSecret(bobKeys.publicKey)

The raw shared secret output should not be used directly as a key. Use a key derivation function like HKDF to derive actual keys from the shared secret.

For key agreement using Weierstrass curves, see ECDH.

Types

Link copied to clipboard
Link copied to clipboard

Supported XDH curves.

Link copied to clipboard
Link copied to clipboard

An XDH private key that provides shared secret computation via sharedSecretGenerator.

Link copied to clipboard

An XDH public key that provides shared secret computation via sharedSecretGenerator.

Properties

Link copied to clipboard
open override val id: CryptographyAlgorithmId<XDH>

The typed identifier that uniquely distinguishes this algorithm and is used to look it up from a CryptographyProvider.

Functions

Link copied to clipboard

Returns a KeyGenerator that generates XDH key pairs on the given curve.

Link copied to clipboard

Returns a Decoder that decodes XDH private keys on the given curve from the specified PrivateKey.Format.

Link copied to clipboard

Returns a Decoder that decodes XDH public keys on the given curve from the specified PublicKey.Format.