本文整理汇总了PHP中Crypt_Hash::hash方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_Hash::hash方法的具体用法?PHP Crypt_Hash::hash怎么用?PHP Crypt_Hash::hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypt_Hash
的用法示例。
在下文中一共展示了Crypt_Hash::hash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getHMAC
function getHMAC($astrResponseData, $astrFileName, $astrMerchantID)
{
$strkey = $this->getKey($astrMerchantID, $astrFileName);
$strhexkey = $this->hexstr($strkey);
$hash = new Crypt_Hash('sha1');
$hash->setKey($strhexkey);
$digest = $hash->hash($astrResponseData);
$cleardigest = $this->strhex($digest);
return $cleardigest;
}
示例2: encrypt
protected function encrypt($plaintext)
{
if ($this->cipher == NULL) {
$hash = new Crypt_Hash('md5');
$hashed_key = bin2hex($hash->hash($this->application->encryption_key()));
$this->cipher = new Crypt_AES(CRYPT_AES_MODE_CBC);
$this->cipher->setKeyLength(256);
$this->cipher->setKey($hashed_key);
}
$iv = "";
for ($i = 0; $i < 8; $i++) {
$iv .= chr(mt_rand(0, 255));
}
$iv = bin2hex($iv);
$this->cipher->setIV($iv);
return $iv . bin2hex($this->cipher->encrypt($plaintext));
}
示例3: verify
/**
* DSA verify.
*
* @param string $message Message.
* @param string $hash_alg Hash algorithm.
* @param Math_BigInteger $r r.
* @param Math_BigInteger $s s.
*
* @return bool True if verified.
*/
public function verify($message, $hash_alg, $r, $s)
{
$hash = new Crypt_Hash($hash_alg);
$hash_m = new Math_BigInteger($hash->hash($message), 256);
$g = new Math_BigInteger($this->_key->key['g'], 256);
$p = new Math_BigInteger($this->_key->key['p'], 256);
$q = new Math_BigInteger($this->_key->key['q'], 256);
$y = new Math_BigInteger($this->_key->key['y'], 256);
$w = $s->modInverse($q);
$hash_m_mul = $hash_m->multiply($w);
$u1_base = $hash_m_mul->divide($q);
$u1 = $u1_base[1];
$r_mul = $r->multiply($w);
$u2_base = $r_mul->divide($q);
$u2 = $u2_base[1];
$g_pow = $g->modPow($u1, $p);
$y_pow = $y->modPow($u2, $p);
$g_pow_mul = $g_pow->multiply($y_pow);
$g_pow_mul_mod_base = $g_pow_mul->divide($p);
$g_pow_mul_mod = $g_pow_mul_mod_base[1];
$v_base = $g_pow_mul_mod->divide($q);
$v = $v_base[1];
return $v->compare($r) == 0;
}
示例4: setPassword
/**
* Sets the password.
*
* Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
* {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2}:
* $hash, $salt, $count, $dkLen
*
* Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
*
* Note: Could, but not must, extend by the child Crypt_* class
*
* @see Crypt/Hash.php
* @param String $password
* @param optional String $method
* @access public
*/
function setPassword($password, $method = 'pbkdf2')
{
$key = '';
switch ($method) {
default:
// 'pbkdf2'
$func_args = func_get_args();
// Hash function
$hash = isset($func_args[2]) ? $func_args[2] : 'sha1';
// WPA and WPA2 use the SSID as the salt
$salt = isset($func_args[3]) ? $func_args[3] : $this->password_default_salt;
// RFC2898#section-4.2 uses 1,000 iterations by default
// WPA and WPA2 use 4,096.
$count = isset($func_args[4]) ? $func_args[4] : 1000;
// Keylength
$dkLen = isset($func_args[5]) ? $func_args[5] : $this->password_key_size;
// Determining if php[>=5.5.0]'s hash_pbkdf2() function avail- and useable
switch (true) {
case !function_exists('hash_pbkdf2'):
case !function_exists('hash_algos'):
case !in_array($hash, hash_algos()):
if (!class_exists('Crypt_Hash')) {
require_once 'Crypt/Hash.php';
}
$i = 1;
while (strlen($key) < $dkLen) {
$hmac = new Crypt_Hash();
$hmac->setHash($hash);
$hmac->setKey($password);
$f = $u = $hmac->hash($salt . pack('N', $i++));
for ($j = 2; $j <= $count; ++$j) {
$u = $hmac->hash($u);
$f ^= $u;
}
$key .= $f;
}
$key = substr($key, 0, $dkLen);
break;
default:
$key = hash_pbkdf2($hash, $password, $salt, $count, $dkLen, true);
}
}
$this->setKey($key);
}
示例5: setPassword
/**
* Sets the password.
*
* Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
* {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2} or pbkdf1:
* $hash, $salt, $count, $dkLen
*
* Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
*
* Note: Could, but not must, extend by the child Crypt_* class
*
* @see Crypt/Hash.php
* @param String $password
* @param optional String $method
* @return Boolean
* @access public
*/
function setPassword($password, $method = 'pbkdf2')
{
$key = '';
switch ($method) {
default:
// 'pbkdf2' or 'pbkdf1'
$func_args = func_get_args();
// Hash function
$hash = isset($func_args[2]) ? $func_args[2] : 'sha1';
// WPA and WPA2 use the SSID as the salt
$salt = isset($func_args[3]) ? $func_args[3] : $this->password_default_salt;
// RFC2898#section-4.2 uses 1,000 iterations by default
// WPA and WPA2 use 4,096.
$count = isset($func_args[4]) ? $func_args[4] : 1000;
// Keylength
if (isset($func_args[5])) {
$dkLen = $func_args[5];
} else {
$dkLen = $method == 'pbkdf1' ? 2 * $this->password_key_size : $this->password_key_size;
}
switch (true) {
case $method == 'pbkdf1':
if (!class_exists('Crypt_Hash')) {
include_once 'Crypt/Hash.php';
}
$hashObj = new Crypt_Hash();
$hashObj->setHash($hash);
if ($dkLen > $hashObj->getLength()) {
user_error('Derived key too long');
return false;
}
$t = $password . $salt;
for ($i = 0; $i < $count; ++$i) {
$t = $hashObj->hash($t);
}
$key = substr($t, 0, $dkLen);
$this->setKey(substr($key, 0, $dkLen >> 1));
$this->setIV(substr($key, $dkLen >> 1));
return true;
// Determining if php[>=5.5.0]'s hash_pbkdf2() function avail- and useable
// Determining if php[>=5.5.0]'s hash_pbkdf2() function avail- and useable
case !function_exists('hash_pbkdf2'):
case !function_exists('hash_algos'):
case !in_array($hash, hash_algos()):
if (!class_exists('Crypt_Hash')) {
include_once 'Crypt/Hash.php';
}
$i = 1;
while (strlen($key) < $dkLen) {
$hmac = new Crypt_Hash();
$hmac->setHash($hash);
$hmac->setKey($password);
$f = $u = $hmac->hash($salt . pack('N', $i++));
for ($j = 2; $j <= $count; ++$j) {
$u = $hmac->hash($u);
$f ^= $u;
}
$key .= $f;
}
$key = substr($key, 0, $dkLen);
break;
default:
$key = hash_pbkdf2($hash, $password, $salt, $count, $dkLen, true);
}
}
$this->setKey($key);
return true;
}
示例6: setPassword
public function setPassword($password, $method = 'pbkdf2')
{
$key = '';
list(, , $hash, $salt, $count) = func_get_args();
if (!isset($hash)) {
$hash = 'sha1';
}
if (!isset($salt)) {
$salt = 'phpseclib';
}
if (!isset($count)) {
$count = 1000;
}
if (!class_exists('Crypt_Hash')) {
require_once 'Crypt/Hash.php';
}
$i = 1;
while (strlen($key) < $this->key_size) {
$hmac = new Crypt_Hash();
$hmac->setHash($hash);
$hmac->setKey($password);
$f = $u = $hmac->hash($salt . pack('N', $i++));
for ($j = 2; $j <= $count; $j++) {
$u = $hmac->hash($u);
$f ^= $u;
}
$key .= $f;
}
$this->setKey(substr($key, 0, $this->key_size));
}
示例7: _emsa_pkcs1_v1_5_encode
public function _emsa_pkcs1_v1_5_encode($m, $emLen)
{
$h = $this->hash->hash($m);
if ($h === false) {
return false;
}
switch ($this->hashName) {
case 'md2':
$t = pack('H*', '3020300c06082a864886f70d020205000410');
break;
case 'md5':
$t = pack('H*', '3020300c06082a864886f70d020505000410');
break;
case 'sha1':
$t = pack('H*', '3021300906052b0e03021a05000414');
break;
case 'sha256':
$t = pack('H*', '3031300d060960864801650304020105000420');
break;
case 'sha384':
$t = pack('H*', '3041300d060960864801650304020205000430');
break;
case 'sha512':
$t = pack('H*', '3051300d060960864801650304020305000440');
}
$t .= $h;
$tLen = strlen($t);
if ($emLen < $tLen + 11) {
user_error('Intended encoded message length too short');
return false;
}
$ps = str_repeat(chr(255), $emLen - $tLen - 3);
$em = '' . "" . '' . $ps . '' . "" . '' . $t;
return $em;
}
示例8: switch
/**
* EMSA-PKCS1-V1_5-ENCODE
*
* See {@link http://tools.ietf.org/html/rfc3447#section-9.2 RFC3447#section-9.2}.
*
* @access private
* @param String $m
* @param Integer $emLen
* @return String
*/
function _emsa_pkcs1_v1_5_encode($m, $emLen)
{
$h = $this->hash->hash($m);
if ($h === false) {
return false;
}
// see http://tools.ietf.org/html/rfc3447#page-43
switch ($this->hashName) {
case 'md2':
$t = pack('H*', '3020300c06082a864886f70d020205000410');
break;
case 'md5':
$t = pack('H*', '3020300c06082a864886f70d020505000410');
break;
case 'sha1':
$t = pack('H*', '3021300906052b0e03021a05000414');
break;
case 'sha256':
$t = pack('H*', '3031300d060960864801650304020105000420');
break;
case 'sha384':
$t = pack('H*', '3041300d060960864801650304020205000430');
break;
case 'sha512':
$t = pack('H*', '3051300d060960864801650304020305000440');
}
$t .= $h;
$tLen = strlen($t);
if ($emLen < $tLen + 11) {
user_error('Intended encoded message length too short', E_USER_NOTICE);
return false;
}
$ps = str_repeat(chr(0xff), $emLen - $tLen - 3);
$em = "{$ps}{$t}";
return $em;
}
示例9: getTokenTime
private static final function getTokenTime($username, $url)
{
use_helper('Hash');
$hash = new Crypt_Hash('sha256');
$time = 0;
if ($token = Record::findOneFrom('SecureToken', "username = ? AND url = ?", array($username, bin2hex($hash->hash($url))))) {
$time = $token->time;
}
return $time;
}
示例10: _bakeCookie
private function _bakeCookie($time, $user)
{
if (!$this->_validateObject($user, true)) {
return false;
}
use_helper("Hash");
$hash = new Crypt_Hash("sha256");
$cookie = "exp=" . $time . "&id=" . $user->id . "&digest=" . bin2hex($hash->hash($user->username . $user->salt));
return $cookie;
}
示例11: _hashBody
/**
*
*
*/
protected static function _hashBody($body, $method = 'sha1')
{
// prefer to use phpseclib
// http://phpseclib.sourceforge.net
if (class_exists('Crypt_Hash')) {
$hash = new Crypt_Hash($method);
return base64_encode($hash->hash($body));
} else {
// try standard PHP hash function
return base64_encode(hash($method, $body, true));
}
}
示例12: substr
/**
* EMSA-PSS-VERIFY
*
* See {@link http://tools.ietf.org/html/rfc3447#section-9.1.2 RFC3447#section-9.1.2}.
*
* @access private
* @param String $m
* @param String $em
* @param Integer $emBits
* @return String
*/
function _emsa_pss_verify($m, $em, $emBits)
{
// if $m is larger than two million terrabytes and you're using sha1, PKCS#1 suggests a "Label too long" error
// be output.
$emLen = $emBits + 1 >> 3;
// ie. ceil($emBits / 8);
$sLen = $this->sLen == false ? $this->hLen : $this->sLen;
$mHash = $this->hash->hash($m);
if ($emLen < $this->hLen + $sLen + 2) {
return false;
}
if ($em[strlen($em) - 1] != chr(0xbc)) {
return false;
}
$maskedDB = substr($em, 0, -$this->hLen - 1);
$h = substr($em, -$this->hLen - 1, $this->hLen);
$temp = chr(0xff << ($emBits & 7));
if ((~$maskedDB[0] & $temp) != $temp) {
return false;
}
$dbMask = $this->_mgf1($h, $emLen - $this->hLen - 1);
$db = $maskedDB ^ $dbMask;
$db[0] = ~chr(0xff << ($emBits & 7)) & $db[0];
$temp = $emLen - $this->hLen - $sLen - 2;
if (substr($db, 0, $temp) != str_repeat(chr(0), $temp) || ord($db[$temp]) != 1) {
return false;
}
$salt = substr($db, $temp + 1);
// should be $sLen long
$m2 = "" . $mHash . $salt;
$h2 = $this->hash->hash($m2);
return $this->_equals($h, $h2);
}
示例13: getTokenTime
private static final function getTokenTime($username, $url)
{
use_helper('Hash');
$hash = new Crypt_Hash('sha256');
$time = 0;
$token = self::findOne(array('where' => 'username = :username AND url = :url', 'values' => array(':username' => $username, ':url' => bin2hex($hash->hash($url)))));
if ($token) {
$time = $token->time;
}
return $time;
}
示例14: setPassword
public function setPassword($password, $method)
{
$key = "";
switch (1) {
default:
list(, , $hash, $salt, $count) = func_get_args();
if (!$hash) {
$hash = "sha1";
}
if (!$salt) {
$salt = "phpseclib";
}
if (!$count) {
$count = 1000;
}
if (!class_exists("Crypt_Hash")) {
require_once "Crypt/Hash.php";
}
$i = 1;
while (strlen($key) < $this->key_size) {
$hmac = new Crypt_Hash();
$hmac->setHash($hash);
$hmac->setKey($password);
$f = $u = $hmac->hash($salt . pack("N", $i++));
for ($j = 2; $j <= $count; $j++) {
$u = $hmac->hash($u);
$f ^= $u;
}
$key .= $f;
}
}
$this->setKey(substr($key, 0, $this->key_size));
}
示例15: generateHashedPassword
/**
* Generates a hashed version of a password.
*
* @see Hash Helper
*
* @param <type> $password
* @param <type> $salt
* @return <type>
*/
public static final function generateHashedPassword($password, $salt)
{
use_helper('Hash');
$hash = new Crypt_Hash('sha512');
return bin2hex($hash->hash($password . $salt));
}