openssl_dh_compute_key

PHP 5 >= 5.3.0, PHP 7, PHP 8
openssl_dh_compute_key - Computes shared secret for public value of remote DH public key and local DH key
Manual
Code Examples

openssl_dh_compute_key( string$public_key, OpenSSLAsymmetricKey$private_key ): string|false

The shared secret returned by openssl_dh_compute_key is often used as an encryption key to secretly communicate with a remote party. This is known as the Diffie-Hellman key exchange.

Note:

ECDH is only supported as of PHP 8.1.0 and OpenSSL 3.0.0.

Parameters

public_key

DH Public key of the remote party.

private_key

A local DH private key, corresponding to the public key to be shared with the remote party.

Return Values

Returns shared secret on success or false on failure.

Changelog

Version Description
8.0.0 private_key accepts an OpenSSLAsymmetricKey now; previously, a resource of type OpenSSL key was accepted.

Related Functions

Example of openssl_dh_compute_key

Show all examples for openssl_dh_compute_key

PHP Version:


Function openssl_dh_compute_key:

OpenSSL Functions

Most used PHP functions