当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_OpenId::strlen方法代码示例

本文整理汇总了PHP中Zend_OpenId::strlen方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_OpenId::strlen方法的具体用法?PHP Zend_OpenId::strlen怎么用?PHP Zend_OpenId::strlen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_OpenId的用法示例。


在下文中一共展示了Zend_OpenId::strlen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _associate


//.........这里部分代码省略.........
                 if (is_array($x) && count($x) == 2) {
                     list($key, $value) = $x;
                     $r[trim($key)] = trim($value);
                 } else {
                     $bad_response = true;
                 }
             }
         }
         if ($bad_response && strpos($ret, 'Unknown session type') !== false) {
             $r['error_code'] = 'unsupported-type';
         }
         $ret = $r;
         if (isset($ret['error_code']) && $ret['error_code'] == 'unsupported-type') {
             if ($params['openid.session_type'] == 'DH-SHA256') {
                 $params['openid.session_type'] = 'DH-SHA1';
                 $params['openid.assoc_type'] = 'HMAC-SHA1';
             } else {
                 if ($params['openid.session_type'] == 'DH-SHA1') {
                     $params['openid.session_type'] = 'no-encryption';
                 } else {
                     $this->_setError("The OpenID service responded with: " . $ret['error_code']);
                     return false;
                 }
             }
         } else {
             break;
         }
     }
     if ($status != 200) {
         $this->_setError("The server responded with status code: " . $status);
         return false;
     }
     if ($version >= 2.0 && isset($ret['ns']) && $ret['ns'] != Zend_OpenId::NS_2_0) {
         $this->_setError("Wrong namespace definition in the server response");
         return false;
     }
     if (!isset($ret['assoc_handle']) || !isset($ret['expires_in']) || !isset($ret['assoc_type']) || $params['openid.assoc_type'] != $ret['assoc_type']) {
         if ($params['openid.assoc_type'] != $ret['assoc_type']) {
             $this->_setError("The returned assoc_type differed from the supplied openid.assoc_type");
         } else {
             $this->_setError("Missing required data from provider (assoc_handle, expires_in, assoc_type are required)");
         }
         return false;
     }
     $handle = $ret['assoc_handle'];
     $expiresIn = $ret['expires_in'];
     if ($ret['assoc_type'] == 'HMAC-SHA1') {
         $macFunc = 'sha1';
     } else {
         if ($ret['assoc_type'] == 'HMAC-SHA256' && $version >= 2.0) {
             $macFunc = 'sha256';
         } else {
             $this->_setError("Unsupported assoc_type");
             return false;
         }
     }
     if ((empty($ret['session_type']) || $version >= 2.0 && $ret['session_type'] == 'no-encryption') && isset($ret['mac_key'])) {
         $secret = base64_decode($ret['mac_key']);
     } else {
         if (isset($ret['session_type']) && $ret['session_type'] == 'DH-SHA1' && !empty($ret['dh_server_public']) && !empty($ret['enc_mac_key'])) {
             $dhFunc = 'sha1';
         } else {
             if (isset($ret['session_type']) && $ret['session_type'] == 'DH-SHA256' && $version >= 2.0 && !empty($ret['dh_server_public']) && !empty($ret['enc_mac_key'])) {
                 $dhFunc = 'sha256';
             } else {
                 $this->_setError("Unsupported session_type");
                 return false;
             }
         }
     }
     if (isset($dhFunc)) {
         $serverPub = base64_decode($ret['dh_server_public']);
         $dhSec = Zend_OpenId::computeDhSecret($serverPub, $dh);
         if ($dhSec === false) {
             $this->_setError("DH secret comutation failed");
             return false;
         }
         $sec = Zend_OpenId::digest($dhFunc, $dhSec);
         if ($sec === false) {
             $this->_setError("Could not create digest");
             return false;
         }
         $secret = $sec ^ base64_decode($ret['enc_mac_key']);
     }
     if ($macFunc == 'sha1') {
         if (Zend_OpenId::strlen($secret) != 20) {
             $this->_setError("The length of the sha1 secret must be 20");
             return false;
         }
     } else {
         if ($macFunc == 'sha256') {
             if (Zend_OpenId::strlen($secret) != 32) {
                 $this->_setError("The length of the sha256 secret must be 32");
                 return false;
             }
         }
     }
     $this->_addAssociation($url, $handle, $macFunc, $secret, time() + $expiresIn);
     return true;
 }
开发者ID:kassimentz,项目名称:Estudos-Zend-Framework,代码行数:101,代码来源:Consumer.php

示例2: createDhKey

 /**
  * Performs the first step of a Diffie-Hellman key exchange by generating
  * private and public DH values based on given prime number $p and
  * generator $g. Both sides of key exchange MUST have the same prime number
  * and generator. In this case they will able to create a random shared
  * secret that is never send from one to the other.
  *
  * @param string $p prime number in binary representation
  * @param string $g generator in binary representation
  * @param string $priv_key private key in binary representation
  * @return mixed
  */
 public static function createDhKey($p, $g, $priv_key = null)
 {
     if (function_exists('openssl_dh_compute_key')) {
         $dh_details = array('p' => $p, 'g' => $g);
         if ($priv_key !== null) {
             $dh_details['priv_key'] = $priv_key;
         }
         return openssl_pkey_new(array('dh' => $dh_details));
     } else {
         $bn_p = self::binToBigNum($p);
         $bn_g = self::binToBigNum($g);
         if ($priv_key === null) {
             $priv_key = self::randomBytes(Zend_OpenId::strlen($p));
         }
         $bn_priv_key = self::binToBigNum($priv_key);
         if (extension_loaded('gmp')) {
             $bn_pub_key = gmp_powm($bn_g, $bn_priv_key, $bn_p);
         } else {
             if (extension_loaded('bcmath')) {
                 $bn_pub_key = bcpowmod($bn_g, $bn_priv_key, $bn_p);
             }
         }
         $pub_key = self::bigNumToBin($bn_pub_key);
         return array('p' => $bn_p, 'g' => $bn_g, 'priv_key' => $bn_priv_key, 'pub_key' => $bn_pub_key, 'details' => array('p' => $p, 'g' => $g, 'priv_key' => $priv_key, 'pub_key' => $pub_key));
     }
 }
开发者ID:jpbender,项目名称:mage_virtual,代码行数:38,代码来源:OpenId.php


注:本文中的Zend_OpenId::strlen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。