Auth_OpenID_DiffieHellman::xorSecret PHP Метод

xorSecret() публичный Метод

public xorSecret ( $composite, $secret, $hash_func )
    function xorSecret($composite, $secret, $hash_func)
    {
        $dh_shared = $this->getSharedSecret($composite);
        $dh_shared_str = $this->lib->longToBinary($dh_shared);
        $hash_dh_shared = $hash_func($dh_shared_str);
        $xsecret = "";
        for ($i = 0; $i < Auth_OpenID::bytes($secret); $i++) {
            $xsecret .= chr(ord($secret[$i]) ^ ord($hash_dh_shared[$i]));
        }
        return $xsecret;
    }

Usage Example

Пример #1
0
 function test_dh()
 {
     if (!defined('Auth_OpenID_NO_MATH_SUPPORT')) {
         $dh = new Auth_OpenID_DiffieHellman();
         $ml =& Auth_OpenID_getMathLib();
         $cpub = $dh->public;
         $session = new Auth_OpenID_DiffieHellmanServerSession(new Auth_OpenID_DiffieHellman(), $cpub);
         $this->request = new Auth_OpenID_AssociateRequest($session);
         $response = $this->request->answer($this->assoc);
         $this->assertEquals(Auth_OpenID::arrayGet($response->fields, "assoc_type"), "HMAC-SHA1");
         $this->assertEquals(Auth_OpenID::arrayGet($response->fields, "assoc_handle"), $this->assoc->handle);
         $this->assertFalse(Auth_OpenID::arrayGet($response->fields, "mac_key"));
         $this->assertEquals(Auth_OpenID::arrayGet($response->fields, "session_type"), "DH-SHA1");
         $this->assertTrue(Auth_OpenID::arrayGet($response->fields, "enc_mac_key"));
         $this->assertTrue(Auth_OpenID::arrayGet($response->fields, "dh_server_public"));
         $enc_key = base64_decode(Auth_OpenID::arrayGet($response->fields, "enc_mac_key"));
         $spub = $ml->base64ToLong(Auth_OpenID::arrayGet($response->fields, "dh_server_public"));
         $secret = $dh->xorSecret($spub, $enc_key);
         $this->assertEquals($secret, $this->assoc->secret);
     }
 }
All Usage Examples Of Auth_OpenID_DiffieHellman::xorSecret