dev-master
9999999-devA DiffieHellman implementation in PHP
MIT
The Requires
by Hamza ESSAYEGH
v1
1.0.0.0A DiffieHellman implementation in PHP
MIT
The Requires
by Hamza ESSAYEGH
A DiffieHellman implementation in PHP
A Diffie Helmann implementation in PHP written by Hamza ESSAYEGH, (*2)
First of all, download and install Composer by following the official instructions and the php-gmp
library for your distribution, (*3)
# Debian like installation $ sudo apt-get install php-gmp
Then, you can install this implementation by running the following command:, (*4)
$ composer require querdos/php-dh
Simple example on how to generate a shared secret, (*5)
<?php require_once 'vendor/autoload.php'; use Querdos\DiffieHellman; // alice and bob generate their data and exchange public ones $dh_bob = new DiffieHellman(); $dh_alice = new DiffieHellman(null, $dh_bob->getModulus(), $dh_bob->getBase()); // first initialization for both alice and bob (private and public keys generation) $dh_bob->init(); $dh_alice->init(); // generating a shared secret with corresponding public keys $dh_alice->compute_secret($dh_bob->getPublic()); $dh_bob->compute_secret($dh_alice->getPublic()); if (0 == gmp_cmp($dh_alice->getSecret(), $dh_bob->getSecret())) { echo "Alice and Bob share the same secret" . PHP_EOL; } else { echo "Alice and Bob don't share the same secret" . PHP_EOL; }
In order to compute the secret and according to the corresponding RFC, there is a set of predefined values for g and p. You can specify which one you want in the constructor:, (*6)
<?php $dh = new DiffieHellman(); // no value, 1536bits by default $dh = new DiffieHellman(self::PREDEFINED_1536); // 1536bits length $dh = new DiffieHellman(self::PREDEFINED_3072); // 3072bits length $dh = new DiffieHellman(self::PREDEFINED_4096); // 4096bits length $dh = new DiffieHellman(self::PREDEFINED_6144); // 6144bits length $dh = new DiffieHellman(self::PREDEFINED_8192); // 8192bits length
A DiffieHellman implementation in PHP
MIT
A DiffieHellman implementation in PHP
MIT