• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 827
  • Last Modified:

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.  
0
ucsdmbdm
Asked:
ucsdmbdm
  • 9
  • 6
  • 2
1 Solution
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 9
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now