Deffee-Herman Key Exchange (Diffie–hellman) algorithm principle and PHP implementation version _php tutorial

Source: Internet
Author: User

Deffee-Herman Key Exchange (Diffie–hellman) algorithm principle and PHP implementation version


This article mainly introduces the Deffee-Herman Key Exchange (Diffie–hellman) algorithm principle and PHP implementation version, the need for friends can refer to the following

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%p by 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:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

Include ' diffiehellman.php ';

/*

* Alice:prime = 563

* Generator = 5

* Private key = 9

* Bob:prime = 563

* Generator = 5

* Private key = 14

*/

$p = 563;

$g = 5;

$alice = new Crypt_diffiehellman ($p, $g, 9);

$alice _pubkey = $alice->generatekeys ()->getpublickey ();

$bob = new Crypt_diffiehellman ($p, $g, 14);

$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

http://www.bkjia.com/PHPjc/1000098.html www.bkjia.com true http://www.bkjia.com/PHPjc/1000098.html techarticle Deffee-Herman Key Exchange (Diffie–hellman) algorithm principle and PHP implementation version This article mainly introduces the Deffee-Herman Key Exchange (Diffiehellman) algorithm principle and the PHP implementation version, need ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.