0

PHP Hash Algorithms

posted on June 07, 2010 06:06 AM by Jhoy Imperial
under PHP, Web development

A hash is a non-reversible fixed length string typically used to encrypt important data like your passwords to your database. MD5 and Sha1 are the most-commonly used hash algorithms used for securing data. But as most developers know, there are already applications that could decrypt these hashes. Thus, we add ‘seeds’ or random strings to the password before encrypting them.

If you are looking for other ways to encrypt your data, you could use the PHP function hash_algos() to see a list of available hash algorithms.

print_r(hash_algos());

The above code would output something like:

Array
(
[0] => md4
[1] => md5
[2] => sha1
[3] => sha256
[4] => sha384
[5] => sha512
[6] => ripemd128
[7] => ripemd160
[8] => whirlpool
[9] => tiger128,3
[10] => tiger160,3
[11] => tiger192,3
[12] => tiger128,4
[13] => tiger160,4
[14] => tiger192,4
[15] => snefru
[16] => gost
[17] => adler32
[18] => crc32
[19] => crc32b
[20] => haval128,3
[21] => haval160,3
[22] => haval192,3
[23] => haval224,3
[24] => haval256,3
[25] => haval128,4
[26] => haval160,4
[27] => haval192,4
[28] => haval224,4
[29] => haval256,4
[30] => haval128,5
[31] => haval160,5
[32] => haval192,5
[33] => haval224,5
[34] => haval256,5
)

You could calculate the hash of a string using the function hash(). Example:

$hashed_string = hash('md5', 'apple');
// Value is '1f3870be274f6c49b3e31a0c6728957f'

$hashed_string = hash('adler32', 'banana');
// Value is '62024f08'

:) Thanks for reading!

Recent Tweets

Sponsored Links

Recent Comments

 

"Minimalist Cereal 2"
design and theme by Jhoy Imperial

Email us at support@codingcereal.com

Copyright 2010 - 2011 © www.codingcereal.com