_hash_hmac() WP 3.2.0
Internal compat function to mimic hash_hmac().
Эта функция считается внутренней для использования самим ядром. Не рекомендуется использовать эту функцию в своем коде.
Хуков нет.
Возвращает
Строку/false
. The hash in output determined by $raw_output. False if $algo is unknown or invalid.
Использование
_hash_hmac( $algo, $data, $key, $raw_output );
- $algo(строка) (обязательный)
- Hash algorithm. Accepts 'md5' or 'sha1'.
- $data(строка) (обязательный)
- Data to be hashed.
- $key(строка) (обязательный)
- Secret key to use for generating the hash.
- $raw_output(true|false)
- Whether to output raw binary data (true), or lowercase hexits (false).
По умолчанию: false
Список изменений
С версии 3.2.0 | Введена. |
Код _hash_hmac() hash hmac WP 5.7.1
function _hash_hmac( $algo, $data, $key, $raw_output = false ) {
$packs = array(
'md5' => 'H32',
'sha1' => 'H40',
);
if ( ! isset( $packs[ $algo ] ) ) {
return false;
}
$pack = $packs[ $algo ];
if ( strlen( $key ) > 64 ) {
$key = pack( $pack, $algo( $key ) );
}
$key = str_pad( $key, 64, chr( 0 ) );
$ipad = ( substr( $key, 0, 64 ) ^ str_repeat( chr( 0x36 ), 64 ) );
$opad = ( substr( $key, 0, 64 ) ^ str_repeat( chr( 0x5C ), 64 ) );
$hmac = $algo( $opad . pack( $pack, $algo( $ipad . $data ) ) );
if ( $raw_output ) {
return pack( $pack, $hmac );
}
return $hmac;
}