mhash_count

Gets the highest available hash ID

说明

int mhash_count ( void )

Gets the highest available hash ID.

返回值

Returns the highest available hash ID. Hashes are numbered from 0 to this hash ID.

范例

示例 #1 Traversing all hashes

<?php

$nr = mhash_count();

for ($i = 0; $i <= $nr; $i++) {
    echo sprintf("The blocksize of %s is %d\n",
        mhash_get_hash_name($i),
        mhash_get_block_size($i));
}
?>

mhash_get_block_size

Gets the block size of the specified hash

说明

int mhash_get_block_size ( int $hash )

Gets the size of a block of the specified hash.

参数

hash
The hash ID. One of the MHASH_hashname constants.

返回值

Returns the size in bytes or FALSE, if the hash does not exist.

范例

示例 #1 mhash_get_block_size Example

<?php

echo mhash_get_block_size(MHASH_MD5); // 16

?>

mhash_get_hash_name

Gets the name of the specified hash

说明

string mhash_get_hash_name ( int $hash )

Gets the name of the specified hash.

参数

hash
The hash ID. One of the MHASH_hashname constants.

返回值

Returns the name of the hash or FALSE, if the hash does not exist.

范例

示例 #1 mhash_get_hash_name Example

<?php

echo mhash_get_hash_name(MHASH_MD5); // MD5

?>

mhash_keygen_s2k

Generates a key

说明

string mhash_keygen_s2k ( int $hash , string $password , string $salt , int $bytes )

Generates a key according to the given hash, using an user provided password.

This is the Salted S2K algorithm as specified in the OpenPGP document (» RFC 2440).

Keep in mind that user supplied passwords are not really suitable to be used as keys in cryptographic algorithms, since users normally choose keys they can write on keyboard. These passwords use only 6 to 7 bits per character (or less). It is highly recommended to use some kind of transformation (like this function) to the user supplied key.

参数

hash
The hash ID used to create the key. One of the MHASH_hashname constants.

password
An user supplied password.

salt
Must be different and random enough for every key you generate in order to create different keys. Because salt must be known when you check the keys, it is a good idea to append the key to it. Salt has a fixed length of 8 bytes and will be padded with zeros if you supply less bytes.

bytes
The key length, in bytes.

返回值

Returns the generated key as a string, or FALSE on error.

mhash

Computes hash

说明

string mhash ( int $hash , string $data [, string $key ] )

mhash applies a hash function specified by hash to the data.

参数

hash
The hash ID. One of the MHASH_hashname constants.

data
The user input, as a string.

key
If specified, the function will return the resulting HMAC instead. HMAC is keyed hashing for message authentication, or simply a message digest that depends on the specified key. Not all algorithms supported in mhash can be used in HMAC mode.

返回值

Returns the resulting hash (also called digest) or HMAC as a string, or FALSE on error.

目录