PHP5 windows use sha256

HI,
I've been trying to get Sha-2 family (Sha256) to work with PHP5 (5.23) running on windows. However, I am not sure how to perform that function. I tried the hash function but php is not recognizing that function.  
ucsdmbdmAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lpxtechCommented:
Hi,

what version of php5 do you have? if you have version 5.1.2, then you can use the hash() function like so.

hash('sha256', 'String to hash');
0
ucsdmbdmAuthor Commented:
I have 5.23 but there is no hash function !
0
ucsdmbdmAuthor Commented:
I am afraid this has to do with the fact that I am running a windows version of php. sha1 and md5 seem to be working but can't get has or sha256 to work

Thanks,

0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

lpxtechCommented:
Are you getting an error? if so, will you post it here? Also, you can try putting this bit in your code to see if you have any of the algo's with the hash function. print_r(hash_algos());
0
ucsdmbdmAuthor Commented:
Not really, I don't get any errors. I also tried the code you provided before and nothing was printed ! I am afraid I am missing a hash.dll file. I hate windows servers :)

0
NoiSCommented:
The hash function is available for PHP >= 5.1.2

I'm using PHP 5.1.6 and this code
echo hash('sha256','something to be hashed');
outputs
f3627e80439b402951590e72147845c1fe2fd55ee82158b3e47e4a70abe12f96

If you don't have the hash function it would be installed by pecl
Inside php install path do
> pecl install hash



Try with this code

if (function_exists('hash')){
   echo hash('sha256','something to be hashed');
}else{
  echo 'The hash function isn't available for your system';
}

Open in new window

0
ucsdmbdmAuthor Commented:
Hi,
Thanks for the reply. My php version is 5.2.2. However, I am working on windows server for the first time and not sure how to add in the Hash function to the windows version of the PHP.

0
NoiSCommented:
Accordin with your question you did make the test with the code above and the function isn't available.

To install pecl extensions you must have pecl support installed.

Usualy on php install dir have a file named go-pear.bat. Just give a double click and the extension will be installed.
After you must open a DOS prompt and execute the command
> pecl install hash

maybe this link will be usefull
http://pecl.php.net/package/hash
0
ucsdmbdmAuthor Commented:
Hi  & thanks for the reply  
The install went through completely but I get the following error when I run that command in the ms-dos:
ERROR: THE DSP hash.dsp does not exist

0
ucsdmbdmAuthor Commented:
Hi Agaim,
When i type pecl list I get no packages installed and when I typed in pecl list-all, I didnt get hash as a package.

0
ucsdmbdmAuthor Commented:
I attached screenshots for you as well
Picture-2.png
Picture-3.png
0
NoiSCommented:
So,
try using de final dll found here
http://pecl4win.php.net/ext.php/php_hash.dll
0
ucsdmbdmAuthor Commented:
Hey NoiS,
Can you explain a little further. I downloaded the php_hash.dll from the link u sent but not sure what to do.

0
NoiSCommented:
Put the dll into your extension dir (on php.ini is the directive 'extension_dir')

add this line to your php.ini

extension=php_hash.dll


Usually the php.ini is under php install dir or windows dir and the extension dir is 'ext' dir inside php install dir

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NoiSCommented:
don't forger to restar your webserver
0
ucsdmbdmAuthor Commented:
Thanks,
I got it to work
I also found a mhash extension in my php.ini (not sure whether they were doing the same thing)
One more question:
I have php.ini in D:\php, D:\Program Files\PHP, D:\Windows
Do you know which one is the main one ? I updated all three for this question  
0
NoiSCommented:
To know what is your really php.ini simply run a page with
<?php
  phpinfo();
?>

Look for php.ini on the result page

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.