Diffie-Hellman密钥交换

//header('Content-Type:text/html;charset=utf-8'); //include Diffie Hellman functions require_once 'Crypt/DiffieHellman.php'; //set the required options for two subjects $subject_1 = array('prime'=>'1234567', 'generator'=>'7', 'private'=>'123123455454545'); $subject_2 = array('prime'=>'1234567', 'generator'=>'7', 'private'=>'1123231'); //apply Diffie Hellman algorithm $subject_1_GK = new Crypt_DiffieHellman($subject_1['prime'], $subject_1['generator'], $subject_1['private']); $subject_2_GK = new Crypt_DiffieHellman($subject_2['prime'], $subject_2['generator'],$subject_2['private']); //generate keys $subject_1_GK->generateKeys(); $subject_2_GK->generateKeys(); //compute the secret keys $subject_1_SK = $subject_1_GK->computeSecretKey($subject_2_GK->getPublicKey())->getSharedSecretKey(); $subject_2_SK = $subject_2_GK->computeSecretKey($subject_1_GK->getPublicKey())->getSharedSecretKey(); //displaying the secret keys echo('Subject_1_SK:'.$subject_1_SK.'<br />'); echo('Subject_2_SK:'.$subject_2_SK); 

 

http://pear.php.net/package/Crypt_DiffieHellman/download

你可能感兴趣的:(Algorithm,generator)