Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Need PHP Code for SHA1 function.

Posted on 2004-09-27
6
243 Views
Last Modified: 2008-03-10
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
Comment
Question by:kalmen
  • 3
  • 2
6 Comments
 
LVL 36

Assisted Solution

by:Zyloch
Zyloch earned 20 total points
ID: 12158471
Hi kalmen,

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

Regards,
Zyloch
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 480 total points
ID: 12158620
For a pure PHP-implementation (no extension needed) see (LGPL):

http://www.phpclasses.org/browse/file/200.html
0
 
LVL 1

Author Comment

by:kalmen
ID: 12168152
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 48

Expert Comment

by:hernst42
ID: 12168496
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
 
LVL 1

Author Comment

by:kalmen
ID: 12168688
Let me test it tonight and hopefully get back to you tomorrow with my results.

Thanks
0
 
LVL 1

Author Comment

by:kalmen
ID: 12172761
It worked, Thanks.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question