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

Need PHP Code for SHA1 function.

Hi,
I'm stuck with a verstion of PHP that doesn't support SHA1(). And I mistakenly developed a whole site with it. I found code for a SHA1 function but in Javascript at:
http://pajhome.org.uk/crypt/md5/sha1src.html
But has anyone seen code that I could use? Please help.
0
kalmen
Asked:
kalmen
  • 3
  • 2
2 Solutions
 
ZylochCommented:
Hi kalmen,

Take a look at the comments:
http://us4.php.net/sha1

Regards,
Zyloch
0
 
hernst42Commented:
For a pure PHP-implementation (no extension needed) see (LGPL):

http://www.phpclasses.org/browse/file/200.html
0
 
kalmenAuthor Commented:
I found the class, so I guess my equivalent function would be:

function sha1($inputString) {

  $sha = new SHA;
  $hasharray = $sha->hash_string($inputString);
  return ($sha->hash_to_string( $hasharray ));

}
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
hernst42Commented:
yes

make an if condition around your, if the function already exists, you can use the one defined by php

if (!function_exits('sha1')) {

function sha1($inputString) {

  $sha = new SHA;
  $hasharray = $sha->hash_string($inputString);
  return ($sha->hash_to_string( $hasharray ));

}

}
0
 
kalmenAuthor Commented:
Let me test it tonight and hopefully get back to you tomorrow with my results.

Thanks
0
 
kalmenAuthor Commented:
It worked, Thanks.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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