<?php
$crypted=crypt('myText');
?>
The code above produces crypted text.
But the code below doesn’t produces hased text.
<?php
$hashed=hash('myText');
?>
How to use hash?
<?php
$crypted=crypt('myText');
?>
The code above produces crypted text.
But the code below doesn’t produces hased text.
<?php
$hashed=hash('myText');
?>
How to use hash?
Please see the manual page before using any PHP functions if you are not sure how to use them and what parameters they can have.
hash: - http://www.php.net/manual/en/function.hash.php
crypt: - http://www.php.net/manual/en/function.crypt.php
See how they are used in the examples (parameters required) there and use accordingly.
hash('[COLOR="Red"]ripemd160[/COLOR]', 'The quick brown fox jumped over the lazy dog.');
Do you call ‘ripemd160’ a parameter?
As you can see in the manual that hash() function takes two required parameters and one optional. So you must give two parameters to get the desired value; first parameter is algorithm you want to use (see hash_algos() function for other algorithms you can use) as mentioned in the manual. And second parameter is your text. So your example should look like this:
$hash = hash('ripemd160', 'myText');
echo $hash;
You will see ‘0513a022887d52242b487ca5dd5ddbe3ba97af3e’ as output.
As I test it ‘ripemd160’ is fixed, and ‘myText’ is dynamic.
I am curious why ripemd160 can’t be dynamic.
I mean why “ripemd161” doesn’t work.
See the manual page for [fphp]hash[/fphp].
$algo = Name of selected hashing algorithm (i.e. “md5”, “sha256”, “haval160,4”, etc…)
You can find a list of the available hashing algorithms with [fphp]hash_algos[/fphp].
You can’t just ‘make stuff up’, there are rules you know.
I guess because there’s no algorithm called ‘ripemd161’. Or at least it isn’t available.
It’s like font names. Or telephone numbers
You need to use an algorithm that exists. Like rajug already said, if you don’t want to use ripemd160, see hash_algos() function for other algorithms you can use
Maybe this will help clear things up.
<?php
foreach(hash_algos() as $algo){
printf(
"(%s) - %s\
",
$algo,
hash($algo, 'AnthonySterling')
);
}
/*
(md2) - be820630d60c7bd62fb9912a687cab1f
(md4) - 737222f2fe66751384c0f4a21d770929
(md5) - e4821c8e1c125c813be2cfe890065bab
(sha1) - b20dc6629d1b619c1dbd88fda0c07cea549bbfbc
(sha224) - 8992034e7785dfa5c5de00b17d59ebc39627a11700f426d5e490edab
(sha256) - 60faea7c70a5b220507d7db9e342c11364fe96fe0149d322ddd185f8796e4908
(sha384) - da01760f557e232b2a855ccc00b66d1c55822a3267c9a71d0854198106e4026162799e72ededa3b3ccc7df37addf2f9f
(sha512) - 200947a3dd106b377dfd82a80fc4db399d060024d0176d41996fa0146c00bb64677940ffdf87fa16b2ef2927cb97aa1726e6ac9ae5c95416c7a687833f7a6a3c
(ripemd128) - bf22fcff2c923919475fb9a8ca822f37
(ripemd160) - d27505bb60269dea5d8c80c015ea35e541c01f9a
(ripemd256) - 9d92e7ae95fe8bfecc2439efb3628c4660407747d8bf29c392acde836e97e57c
(ripemd320) - 076f301ff314e11a7841339c1f36d0a2872c5f867f09b54bf3335f3008a4c9f072a6f682ac7ced5d
(whirlpool) - dbac7c925c334d4aadb55e8aa89c03a79fc1d0d52b462864dbb06ef2b118318d582bddb13eecfcdcefe22a3242f5d65351782b27051df3d5498520eb6d41741c
(tiger128,3) - b4390131ba5a21882cad3bd9c3212ab8
(tiger160,3) - b4390131ba5a21882cad3bd9c3212ab8b165da13
(tiger192,3) - b4390131ba5a21882cad3bd9c3212ab8b165da134d626ba7
(tiger128,4) - 2b39c0ef0d1bd80f2aa03ebb7e59a948
(tiger160,4) - 2b39c0ef0d1bd80f2aa03ebb7e59a948e357ea5e
(tiger192,4) - 2b39c0ef0d1bd80f2aa03ebb7e59a948e357ea5e9ff98bf4
(snefru) - 4019c28fafa1a8a3fcfb9f26956c5ab9724f2ac5cfb96f70fc67c63eaef97ba1
(snefru256) - 4019c28fafa1a8a3fcfb9f26956c5ab9724f2ac5cfb96f70fc67c63eaef97ba1
(gost) - 051f7fccff4e93c71d71e8a6d5cca8626ff7f88a198e60e22a54e87ad7177944
(adler32) - 3082062a
(crc32) - 8a20c13b
(crc32b) - e17f7111
(salsa10) - 70bc195d78711b2fae0751e65c539cd0dc7dbf260ced7970eb8880fd0a3a6ee74345e7f575ebb9da5a3528cb04c3171275b47a4b6089e2f0b26e813c119ee6c2
(salsa20) - 494c31bd46fc8b62a7ce8ac99fd6ba8ddc5f1a72e14c31b5e14f0eaba49c20eedfa293a234a4540976ecf9343b2122c5d862f3c5ae10de1b3f46f423a9e1f3ba
(haval128,3) - ef03b82f4bb264877bb71fcacff4945b
(haval160,3) - d5be682340c733905df48527ae4ab8af0be16be1
(haval192,3) - 2fa19d5aae7136cc0e7a50f1e4ee517fa17c70acf61c1b55
(haval224,3) - 616d3a98430ab51aeac08d35ad2ca462667749f16185ae0529ed8630
(haval256,3) - 720a8129bda68cd3ecbdab122c1ef2e944d6af99190c7361de46a02f335e68b2
(haval128,4) - 6f29f6623216f28bf7ce9690a6f100a8
(haval160,4) - 7eac36fa242710ad672da40fe6c293bfeb5fc4ff
(haval192,4) - f2743250e4eba3707ce36b4f3276e39484d505cb5fa92cba
(haval224,4) - abd86e326761da4c226e41e59b7ab3e0b4dff3de92f9f1bd764ae10d
(haval256,4) - acecf16a8252185c3e3b742e694d8a49571e2b33686f5400f188f105f6af582b
(haval128,5) - a8b7209572b93035c99ddca05678f18d
(haval160,5) - f904d217166501c80714c2465c09e4b412ee61ee
(haval192,5) - f2f03219eefe1a7ad4cc6c17231899003692e6b094cff0c2
(haval224,5) - c86c8476c122f4d36520657c91690bbe87c71e5fae072f7a66ef4882
(haval256,5) - 379d64859d70e421f0bff7ff50f7b45dd96d0feb6b4d8f37015129761e843a24
*/
[fphp]hash_algos[/fphp]
There are 35 algos in the page.
The following question sounds like stupid, I like to ask it for confirmation.
Which is the most secure?
Have a read of this, there are some great points/observations made.