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


PHP PassHash::hmac方法代码示例

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


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

示例1: test_hmac

 function test_hmac()
 {
     // known hashes taken from https://code.google.com/p/yii/issues/detail?id=1942
     $this->assertEquals('df08aef118f36b32e29d2f47cda649b6', PassHash::hmac('md5', 'data', 'secret'));
     $this->assertEquals('9818e3306ba5ac267b5f2679fe4abd37e6cd7b54', PassHash::hmac('sha1', 'data', 'secret'));
     // known hashes from https://en.wikipedia.org/wiki/Hash-based_message_authentication_code
     $this->assertEquals('74e6f7298a9c2d168935f58c001bad88', PassHash::hmac('md5', '', ''));
     $this->assertEquals('fbdb1d1b18aa6c08324b7d64b71fb76370690e1d', PassHash::hmac('sha1', '', ''));
     $this->assertEquals('80070713463e7749b90c2dc24911e275', PassHash::hmac('md5', 'The quick brown fox jumps over the lazy dog', 'key'));
     $this->assertEquals('de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9', PassHash::hmac('sha1', 'The quick brown fox jumps over the lazy dog', 'key'));
 }
开发者ID:rsnitsch,项目名称:dokuwiki,代码行数:11,代码来源:PassHash.test.php

示例2: test_ml_imgresize_array_external

 function test_ml_imgresize_array_external()
 {
     global $conf;
     $conf['useslash'] = 0;
     $conf['userewrite'] = 0;
     $ids = array('https://example.com/lib/tpl/dokuwiki/images/logo.png', 'http://example.com/lib/tpl/dokuwiki/images/logo.png', 'ftp://example.com/lib/tpl/dokuwiki/images/logo.png');
     $w = 80;
     $args = array('w' => $w);
     foreach ($ids as $id) {
         $tok = media_get_token($id, $w, 0);
         $hash = substr(PassHash::hmac('md5', $id, auth_cookiesalt()), 0, 6);
         $expect = DOKU_BASE . $this->script . '?w=' . $w . '&tok=' . $tok . '&media=' . rawurlencode($id);
         $this->assertEquals($expect, ml($id, $args));
     }
     $h = 50;
     $args = array('h' => $h);
     $tok = media_get_token($id, $h, 0);
     $expect = DOKU_BASE . $this->script . '?h=' . $h . '&tok=' . $tok . '&media=' . rawurlencode($id);
     $this->assertEquals($expect, ml($id, $args));
     $w = 80;
     $h = 50;
     $args = array('w' => $w, 'h' => $h);
     $tok = media_get_token($id, $w, $h);
     $expect = DOKU_BASE . $this->script . '?w=' . $w . '&h=' . $h . '&tok=' . $tok . '&media=' . rawurlencode($id);
     $this->assertEquals($expect, ml($id, $args));
 }
开发者ID:rsnitsch,项目名称:dokuwiki,代码行数:26,代码来源:common_ml.test.php

示例3: getSecurityToken

/**
 * Return a secret token to be used for CSRF attack prevention
 *
 * @author  Andreas Gohr <andi@splitbrain.org>
 * @link    http://en.wikipedia.org/wiki/Cross-site_request_forgery
 * @link    http://christ1an.blogspot.com/2007/04/preventing-csrf-efficiently.html
 *
 * @return  string
 */
function getSecurityToken()
{
    /** @var Input $INPUT */
    global $INPUT;
    return PassHash::hmac('md5', session_id() . $INPUT->server->str('REMOTE_USER'), auth_cookiesalt());
}
开发者ID:splitbrain,项目名称:dokuwiki,代码行数:15,代码来源:common.php

示例4: media_get_token

/**
 * Calculate a token to be used to verify fetch requests for resized or
 * cropped images have been internally generated - and prevent external
 * DDOS attacks via fetch
 *
 * @author Christopher Smith <chris@jalakai.co.uk>
 *
 * @param string  $id    id of the image
 * @param int     $w     resize/crop width
 * @param int     $h     resize/crop height
 * @return string
 */
function media_get_token($id, $w, $h)
{
    // token is only required for modified images
    if ($w || $h || media_isexternal($id)) {
        $token = $id;
        if ($w) {
            $token .= '.' . $w;
        }
        if ($h) {
            $token .= '.' . $h;
        }
        return substr(PassHash::hmac('md5', $token, auth_cookiesalt()), 0, 6);
    }
    return '';
}
开发者ID:yjliugit,项目名称:dokuwiki,代码行数:27,代码来源:media.php

示例5: getSecurityToken

/**
 * Return a secret token to be used for CSRF attack prevention
 *
 * @author  Andreas Gohr <andi@splitbrain.org>
 * @link    http://en.wikipedia.org/wiki/Cross-site_request_forgery
 * @link    http://christ1an.blogspot.com/2007/04/preventing-csrf-efficiently.html
 * @return  string
 */
function getSecurityToken()
{
    return PassHash::hmac('md5', session_id() . $_SERVER['REMOTE_USER'], auth_cookiesalt());
}
开发者ID:omusico,项目名称:isle-web-framework,代码行数:12,代码来源:common.php


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