Which hash algorithms are already built into PHP?

3

Recently I've been looking for hash algorithms that were not the known md5 , sha1 and sha2 , and that have generated hashs smaller than those mentioned.

That's where I caught myself thinking, how do I know which hash algorithms are available for my use in PHP?

    
asked by anonymous 22.09.2014 / 15:20

1 answer

4

PHP already comes with a range of hash algorithms available for use, including it has a specific function to show which algorithms are available, hash_algos() .

When you run this function, it returns a array with all available methods, eg:

print_r(hash_algos());

The code above would print the following:

Array
(
    [0] => md4
    [1] => md5
    [2] => sha1
    [3] => sha256
    [4] => sha384
    [5] => sha512
    [6] => ripemd128
    [7] => ripemd160
    [8] => whirlpool
    // ...

To use a specific algorithm you can use the hash() function, for example:

echo hash("crc32b", "minha-string");
// imprime: 5373ff38
    
22.09.2014 / 15:20