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


PHP hash_final函数代码示例

本文整理汇总了PHP中hash_final函数的典型用法代码示例。如果您正苦于以下问题:PHP hash_final函数的具体用法?PHP hash_final怎么用?PHP hash_final使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: verify

 public function verify($password, $hash)
 {
     $key = hash(self::HASH_PRIMITIVE, $password, true);
     $hash = base64_decode($hash);
     $header = substr($hash, 0, self::HEADER_SIZE);
     $iv = substr($hash, self::HEADER_SIZE, self::IV_LENGTH);
     $ciphertext = substr($hash, self::HEADER_SIZE + self::IV_LENGTH);
     $decrypted = openssl_decrypt($ciphertext, self::CIPHER_PRIMITIVE, $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
     list(, $version, $rounds, $pointerSize, $dataSize) = unpack('C*', $header);
     $iterationCount = pow(2, $rounds);
     $dataSizeDecoded = pow(2, $dataSize);
     if ($version !== 1) {
         throw new \RuntimeException("Unknown version encountered");
     }
     if (strlen($decrypted) !== self::HASH_LENGTH + $iterationCount * $pointerSize) {
         throw new \RuntimeException("Invalid data payload, was it truncated?");
     }
     $h = hash_init(self::HASH_PRIMITIVE);
     for ($i = 0; $i < $iterationCount; $i++) {
         $pointer = substr($decrypted, $i * $pointerSize, $pointerSize);
         hash_update($h, $this->read($pointer, $dataSizeDecoded));
     }
     $test = hash_final($h, true);
     return hash_equals($test, substr($decrypted, $iterationCount * $pointerSize));
 }
开发者ID:ircmaxell,项目名称:ballandchain,代码行数:25,代码来源:Hash.php

示例2: create_hash

 public static function create_hash($data)
 {
     $hash = Config::get('hash');
     $context = hash_init($hash['hash_algorithm'], HASH_HMAC, $hash['hash_general_key']);
     hash_update($context, $data);
     return hash_final($context);
 }
开发者ID:simplymvc,项目名称:simplymvc,代码行数:7,代码来源:Hash.php

示例3: getResponseHeaders

 /**
  * Build a response header
  *
  * @param $buffer
  *    data to be used in response header
  * @return
  *    response header
  */
 static function getResponseHeaders($buffer = '', $uniqueOrigin = FALSE)
 {
     list($resource, $host, $origin, $strkey1, $strkey2, $data) = self::getRequestHeaders($buffer);
     if (!self::validOrigin($origin, $uniqueOrigin)) {
         self::console('Refusing connection from origin %s. Allowed origin(s): %s', array($origin, implode(', ', $uniqueOrigin)));
         return FALSE;
     }
     // find numbers
     $pattern = '/[^\\d]*/';
     $replacement = '';
     $numkey1 = preg_replace($pattern, $replacement, $strkey1);
     $numkey2 = preg_replace($pattern, $replacement, $strkey2);
     // find spaces
     $pattern = '/[^ ]*/';
     $replacement = '';
     $spaces1 = strlen(preg_replace($pattern, $replacement, $strkey1));
     $spaces2 = strlen(preg_replace($pattern, $replacement, $strkey2));
     if ($spaces1 == 0 || $spaces2 == 0 || $numkey1 % $spaces1 != 0 || $numkey2 % $spaces2 != 0) {
         WSHelpers::console('Handshake failed');
         return FALSE;
     }
     $ctx = hash_init('md5');
     hash_update($ctx, pack("N", $numkey1 / $spaces1));
     hash_update($ctx, pack("N", $numkey2 / $spaces2));
     hash_update($ctx, $data);
     $hash_data = hash_final($ctx, TRUE);
     return "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" . "Upgrade: WebSocket\r\n" . "Connection: Upgrade\r\n" . "Sec-WebSocket-Origin: " . $origin . "\r\n" . "Sec-WebSocket-Location: ws://" . $host . $resource . "\r\n" . "\r\n" . $hash_data;
 }
开发者ID:forktheweb,项目名称:Extendible-Web-Socket-Server,代码行数:36,代码来源:helpers.class.php

示例4: computeMd5Hash

 /**
  * Compute a full md5 file hash or compute a partial hash if $limit is present.
  * Returns null on failure.
  *
  * @param string  $realPath
  * @param int     $offset in bytes
  * @param int     $limit  in bytes
  * @param boolean $forcePartialHashing
  *
  * @return null|string
  */
 public function computeMd5Hash($realPath, $offset = 0, $limit = 0, $forcePartialHashing = false)
 {
     if ($limit === 0 && $offset === 0 && !$forcePartialHashing) {
         // md5_file is always faster if we don't chunk the file
         $hash = md5_file($realPath);
         return $hash !== false ? $hash : null;
     }
     $ctx = hash_init('md5');
     if (!$ctx) {
         // Fail to initialize file hashing
         return null;
     }
     // Calculate limit from file size and offset
     if ($limit === 0) {
         $limit = filesize($realPath) - $offset;
     }
     $fh = @fopen($realPath, "rb");
     if ($fh === false) {
         // Failed opening file, cleanup hash context
         hash_final($ctx);
         return null;
     }
     fseek($fh, $offset);
     while ($limit > 0) {
         // Limit chunk size to either our remaining chunk or max chunk size
         $chunkSize = $limit < $this->maxChunkByteSize ? $limit : $this->maxChunkByteSize;
         $limit -= $chunkSize;
         $chunk = fread($fh, $chunkSize);
         hash_update($ctx, $chunk);
     }
     fclose($fh);
     return hash_final($ctx);
 }
开发者ID:jimrucinski,项目名称:Vine,代码行数:44,代码来源:HashComputer.php

示例5: create_git_object_hash

function create_git_object_hash( $p_file ) {
	$t_hash_context = hash_init( 'sha1' );
	hash_update( $t_hash_context, 'blob ' . filesize( $p_file ) . "\x00" );
	hash_update_file( $t_hash_context, $p_file );
	$t_object_hash = hash_final( $t_hash_context );
	return $t_object_hash;
}
开发者ID:rombert,项目名称:mantisbt,代码行数:7,代码来源:check_integrity_inc.php

示例6: getHash

 public static function getHash($algoritmo, $data, $key)
 {
     // $key refuerza la encriptación.
     $hash = hash_init($algoritmo, HASH_HMAC, $key);
     hash_update($hash, $data);
     return hash_final($hash);
 }
开发者ID:japriego,项目名称:publico01,代码行数:7,代码来源:Hash.php

示例7: onClose

 public function onClose()
 {
     // $this->params points to an instance of MD5FilterOutput,
     // owned by caller, that caller will use to read out the hash:
     $this->params->hash = hash_final($this->ctx);
     return true;
 }
开发者ID:krekike,项目名称:sambadav,代码行数:7,代码来源:MD5Filter.php

示例8: close

 /**
  * {@inheritdoc}
  */
 public function close()
 {
     if ($this->stream !== NULL) {
         $this->hash = hash_final($this->md5);
     }
     parent::close();
 }
开发者ID:koolkode,项目名称:webdav,代码行数:10,代码来源:DatabaseInputStream.php

示例9: getBaseMaterial

 public function getBaseMaterial($seedBytes)
 {
     $mac = hash_init('sha256', HASH_HMAC, $this->key);
     hash_update($mac, $seedBytes);
     $data = hash_final($mac, true);
     return $data;
 }
开发者ID:Veivan,项目名称:WABuh,代码行数:7,代码来源:ChainKey.php

示例10: process

 public function process(AssetInterface $asset)
 {
     $hash = hash_init('sha1');
     switch ($this->strategy) {
         case self::STRATEGY_MODIFICATION:
             hash_update($hash, $asset->getLastModified());
             break;
         case self::STRATEGY_CONTENT:
             hash_update($hash, $asset->dump());
             break;
     }
     foreach ($asset as $i => $leaf) {
         if ($sourcePath = $leaf->getSourcePath()) {
             hash_update($hash, $sourcePath);
         } else {
             hash_update($hash, $i);
         }
     }
     $hash = substr(hash_final($hash), 0, 7);
     $url = $asset->getTargetPath();
     $oldExt = pathinfo($url, PATHINFO_EXTENSION);
     $newExt = '-' . $hash . '.' . $oldExt;
     if (!$oldExt || 0 < preg_match('/' . preg_quote($newExt, '/') . '$/', $url)) {
         return;
     }
     $asset->setTargetPath(substr($url, 0, (strlen($oldExt) + 1) * -1) . $newExt);
 }
开发者ID:alexBLR,项目名称:firmware,代码行数:27,代码来源:CacheBustingWorker.php

示例11: test_hash

function test_hash($algo, $init)
{
    echo "\n{$algo}, incremental: ";
    $h = hash_init($algo);
    for ($i = 0; $i < 10; ++$i) {
        hash_update($h, '' . $init * 2 + $i * 17);
    }
    echo '(copying state) ';
    $h2 = hash_copy($h);
    for ($i = 0; $i < 10; ++$i) {
        hash_update($h, '' . $init * 2 + $i * 19);
    }
    var_dump(hash_final($h));
    echo "\n{$algo}, from copied state: ";
    var_dump(hash_final($h2));
    echo "\n{$algo}, HMAC, incremental: ";
    $h = hash_init($algo, HASH_HMAC, 'HMAC key. It can be very long, but in this case it will be rehashed to fit the block size of the hashing algorithm...' . $init * 147);
    for ($i = 0; $i < 10; ++$i) {
        hash_update($h, '' . $init * 4 + $i * 7);
    }
    //echo '(copying state) ';
    //$h2 = hash_copy($h);// causes PHP crashes sometimes, reported as PHP Bug #52240
    for ($i = 0; $i < 10; ++$i) {
        hash_update($h, '' . $init * 3 + $i * 11);
    }
    var_dump(hash_final($h));
    //echo "\n$algo, HMAC, from copied state: ";
    //var_dump(hash_final($h2));// BUG IN PHP, HMAC key is not copied, but only referenced ... hash_final on $h clears the HMAC key in $h2 too...  reported as PHP Bug #52240
    echo "\n{$algo}, at once, short data: ";
    var_dump(hash($algo, 'some string to be hashed ... ' . $init * 123 . ' ...'));
    echo "\n{$algo}, at once, HMAC: ";
    var_dump(hash_hmac($algo, 'some string to be hashed ... ' . $init * 123 . ' ...', 'HMAC key. It can be very long, but in this case it will be rehashed to fit the block size of the hashing algorithm.'));
}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:33,代码来源:hash+functions+#26667.php

示例12: create

 public static function create($algo, $data, $salt)
 {
     $context = hash_init($algo, HASH_HMAC, $salt);
     //$salt => $key
     hash_update($context, $data);
     return hash_final($context);
 }
开发者ID:saptharsh,项目名称:Project-Management-App,代码行数:7,代码来源:Hash.php

示例13: getHash

 /**
  * @return Hash
  */
 public function getHash() : Hash
 {
     $hash = new Hash();
     $hash->setAlgorithm($this->getAlgorithm());
     $hash->setValue(hash_final(hash_copy($this->getHandle()), true));
     return $hash;
 }
开发者ID:blar,项目名称:hash,代码行数:10,代码来源:HashGenerator.php

示例14: test_hash_init

function test_hash_init()
{
    $ctx = hash_init("md5");
    hash_update($ctx, "The quick brown fox ");
    hash_update($ctx, "jumped over the lazy dog.");
    var_dump(hash_final($ctx));
}
开发者ID:afaltz,项目名称:hhvm,代码行数:7,代码来源:ext_hash.php

示例15: testBindWithPlaceholder_Constant

 public function testBindWithPlaceholder_Constant()
 {
     $context = hash_init('md2');
     $hash = partial_any('hash_update', $context, …());
     $hash('oh hi');
     $this->assertSame('6f24cbf6005b9bfc0176abbbe309f0d0', hash_final($context));
 }
开发者ID:tdomarkas,项目名称:functional-php,代码行数:7,代码来源:PartialAnyTest.php


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