本文整理匯總了PHP中Password::strcmpConstantTime方法的典型用法代碼示例。如果您正苦於以下問題:PHP Password::strcmpConstantTime方法的具體用法?PHP Password::strcmpConstantTime怎麽用?PHP Password::strcmpConstantTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Password
的用法示例。
在下文中一共展示了Password::strcmpConstantTime方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: decrypt
public static function decrypt($ciphertext, $key)
{
// Extract MAC and IV from the remainder of the ciphertext
$mac = substr($ciphertext, 0, self::ENCRYPTION_MAC_SIZE);
$iv = substr($ciphertext, self::ENCRYPTION_MAC_SIZE, self::ENCRYPTION_BLOCK_SIZE);
$ciphertext = substr($ciphertext, self::ENCRYPTION_MAC_SIZE + self::ENCRYPTION_BLOCK_SIZE);
// Validate MAC
$mac_key = self::_defuseCompatibleHKDF($key, self::ENCRYPTION_MAC_INFO);
$mac_compare = hash_hmac(self::ENCRYPTION_MAC_ALGO, $iv . $ciphertext, $mac_key, true);
if (!Password::strcmpConstantTime($mac, $mac_compare)) {
return false;
}
// Generate subkey for encryption
$enc_key = self::_defuseCompatibleHKDF($key, self::ENCRYPTION_KEY_INFO);
// Decrypt the ciphertext
$mcrypt_method = str_replace('aes', 'rijndael', self::ENCRYPTION_ALGO);
$plaintext = @mcrypt_decrypt($mcrypt_method, $enc_key, $ciphertext, self::ENCRYPTION_MODE, $iv);
if ($plaintext === false) {
return false;
}
$plaintext = self::_stripPKCS7Padding($plaintext, self::ENCRYPTION_BLOCK_SIZE);
if ($plaintext === false) {
return false;
}
// Return the plaintext
return $plaintext;
}
示例2: verifySignature
/**
* @brief Verify a digital signature
* @param string $signature The signature to verify
* @param string $plaintext The string to verify
* @param string $key Optional key. If empty, default key will be used.
* @return bool
*/
public function verifySignature($signature, $plaintext, $key = null)
{
if ($key === null || $key === '') {
$key = $this->_getSessionKey();
}
// Verify the signature using HMAC
$oPassword = new Password();
$compare = bin2hex(self::_defuseCompatibleHKDF($plaintext, $key));
return $oPassword->strcmpConstantTime($signature, $compare);
}