當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Str::hashSize方法代碼示例

本文整理匯總了PHP中Str::hashSize方法的典型用法代碼示例。如果您正苦於以下問題:PHP Str::hashSize方法的具體用法?PHP Str::hashSize怎麽用?PHP Str::hashSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Str的用法示例。


在下文中一共展示了Str::hashSize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: crypt

 /**
  * Encrypt or decrypt a binary input string.
  * 
  * @param string $input    Input data to encrypt
  * @param string $password Encryption/decryption key to use on input
  * @param string $algo     Hashing algo to generate keystream
  * 
  * @return string
  */
 public static function crypt($input, $password, $algo = 'sha512')
 {
     $chunks = \str_split($input, Str::hashSize($algo));
     foreach ($chunks as $i => &$chunk) {
         $chunk = $chunk ^ \hash($algo, $password . $i, true);
     }
     return \implode($chunks);
 }
開發者ID:dopecode,項目名稱:dcrypt,代碼行數:17,代碼來源:Otp.php

示例2: decrypt

 /**
  * Decrypt cyphertext
  * 
  * @param string $cyphertext Cypher text to decrypt
  * @param string $password   Password that should be used to decrypt input data
  * @param int    $cost       Number of HMAC iterations to perform on key
  * @param string $cipher     Mcrypt cipher
  * @param string $mode       Mcrypt mode
  * @param string $algo       Hashing algorithm to use for internal operations
  * 
  * @return string|boolean Returns false on checksum validation failure
  */
 public static function decrypt($cyphertext, $password, $cost = 0, $cipher = MCRYPT_RIJNDAEL_128, $mode = MCRYPT_MODE_CBC, $algo = 'sha256')
 {
     // Determine that size of the IV in bytes
     $ivsize = \mcrypt_get_iv_size($cipher, $mode);
     // Find the IV at the beginning of the cypher text
     $iv = Str::substr($cyphertext, 0, $ivsize);
     // Gather the checksum portion of the cypher text
     $chksum = Str::substr($cyphertext, $ivsize, Str::hashSize($algo));
     // Gather message portion of cyphertext after iv and checksum
     $message = Str::substr($cyphertext, $ivsize + Str::hashSize($algo));
     // Derive key from password
     $key = self::key($password, $iv, $cost, $cipher, $mode, $algo);
     // Calculate verification checksum
     $verify = self::checksum($message, $iv, $key, $cipher, $mode, $algo);
     // If checksum could not be verified return false
     self::checksumVerify($verify, $chksum);
     // Decrypt unpad return
     return Pkcs7::unpad(\mcrypt_decrypt($cipher, $key, $message, $mode, $iv));
 }
開發者ID:dopecode,項目名稱:dcrypt,代碼行數:31,代碼來源:Mcrypt.php


注:本文中的Str::hashSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。