DH

Classic finite-field Diffie-Hellman (DH) key agreement as defined in RFC 2631.

DH allows two parties to establish a shared secret over an insecure channel using arithmetic in a finite field defined by domain Parameters. Parameters must be generated via parametersGenerator or decoded via parametersDecoder before key pairs can be created. RFC 3526 defines well-known groups that can be decoded from their standard representations.

val params = provider.get(DH).parametersGenerator(2048.bits).generateParameters()
val aliceKeys = params.keyPairGenerator().generateKey()
val bobKeys = params.keyPairGenerator().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 elliptic curves, see ECDH. For Montgomery curves, see XDH.

Types

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

DH domain parameters that provide key pair generation via keyPairGenerator.

Link copied to clipboard

A DH private key that provides shared secret computation via sharedSecretGenerator.

Link copied to clipboard

A DH public key that provides shared secret computation via sharedSecretGenerator.

Properties

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

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 Decoder that decodes DH domain parameters from the specified Parameters.Format.

Link copied to clipboard
abstract fun parametersGenerator(primeSize: BinarySize, privateValueSize: BinarySize? = null): ParametersGenerator<DH.Parameters>

Returns a ParametersGenerator that generates DH domain parameters with the specified primeSize and optional privateValueSize.

Link copied to clipboard

Returns a Decoder that decodes DH private keys from the specified PrivateKey.Format.

Link copied to clipboard

Returns a Decoder that decodes DH public keys from the specified PublicKey.Format.