SHA1 class for PHP4
15 09 2003I’ve written this SHA1 class in PHP quite a while ago but thought I might just put it up in case anyone’s still interested in using it.
The code was ported from Branden Hall’s SHA1 Secure Hash for Flash MX which in turn was based on a JavaScript implementation. You can download the code here, feel free to drop me a line if you’re using it for a particular project that’s always nice to know!
FYI, people running a PHP release above 4.3 can use the built-in sha1() and sha1_file() functions.






erm…where is the code? or am i missing some hidden link here?
Oops, code should be available now
Comparing this with the built in version of, there is a bug somewhere in the encoding. Encoding the string ‘aoo_boo_blih.pdf’ gives an equal hash (between sha1 built in and yours), but changing just one character makes it fail. Encoding ‘ioo_boo_blih.pdf’ gives unequal hashes. What’s going on? Thanks.
Excellent work. We are working with your code to add SHA1 support for older platforms for our game. You will be mentioned in the credits.
Many thanks.
Weee, I just can not make it work… my server is using php v 4.02, and when i use the class it just give me a blank result :S.
Do you know what I’m doing wrong, if I just copypaste the example to see how it works.
OOk, I found 2 things…
I could not use it as a class but breaking the class part in different functions and modifying some $this->bla bla bla. I made it work…
BUT:…
The BIG bug I found… is that dechex may return 00FA
and this will result for the sha1 as FA… taking a big difference with the sha1 original algoritm, so… I just did another SO SIMPLE function…
function zeroL($str){ #If missing 0’s
if(strlen($str)