How does PHP implement the Diffichelman key Exchange (Diffie–hellman) algorithm? This paper mainly introduces the principle of Deffee-Herman Key Exchange (Diffie–hellman) algorithm and the example of PHP implementation. We hope to help you.
Deffee-Herman (Diffie–hellman) is an algorithm that allows both parties to establish secret keys on insecure public channels that can be used to encrypt (such as RC4) content later on.
The Deffee-Herman (Diffie–hellman) algorithm principle is simple:
As a principle, it is easy to prove (g^b%p) ^a%p = (g^a%p) ^b%pby mathematical principles, so they get an identical key.
The public keys above except A, a, B and the last are secret, and others can be passed on the public channel. The actual use of P is very large (more than 300), G usually take 2 or 5. It is almost impossible to work out a (discrete math problem) from P,g and g^a%p.
Many languages have implemented this algorithm, taking Crypt_diffiehellman in PHP package as an example:
<?phpinclude ' diffiehellman.php '; /* * alice:prime = 563 * generator = 5 * Private key = 9 * Bob: prime = 563 * generator = 5 *
private key = */$p = 563; $g = 5; $alice = new Crypt_diffiehellman ($p, $g, 9); $alice _pubkey = $alice->generatekeys () ->getpublickey (); $bob = new Crypt_diffiehellman ($p, $g, +); $bob _pubkey = $bob->generatekeys ()->getpublickey (); $alice _computekey = $alice->computesecretkey ($bob _pubkey)->getsharedsecretkey (); $bob _computekey = $bob Computesecretkey ($alice _pubkey)->getsharedsecretkey (); echo "{$alice _pubkey}-{$bob _pubkey}-{$alice _computekey}-{$bob _computekey}"; 78-534-117-117
Related recommendations:
PHP algorithm split array, without Array_chunk () _php Tutorial
How the PHP algorithm prints out
php how to resolve session deadlock _php tutorial