PHP Classes

File: _classes/SHA1.class.php

Recommend this page to a friend!
  Classes of Marius Zadara  >  Message Digest  >  _classes/SHA1.class.php  >  Download  
File: _classes/SHA1.class.php
Role: Class source
Content type: text/plain
Description: SHA1 hash algorithm
Class: Message Digest
Generate message digests with hashing algorithms
Author: By
Last change:
Date: 13 years ago
Size: 970 bytes
 

Contents

Class file image Download
<?php

/**
 * SHA1 hasher implementation.
 *
 * @author Marius Zadara <marius@zadara.org>
 * @category org.zadara.marius.messagedigester.classes
 * @copyright (C) 2008, Marius Zadara <marius@zadara.org>
 * @license GNU GPL
 * @package org.zadara.marius.messagedigester
 *
 * @final
 * @see IHashAlgorithm
 */
final class SHA1 implements IHashAlgorithm
{
   
/**
     * Hash function implementation.
     *
     * @param string $string The text to hash
     * @param boolean $raw_output Raw output
     * @return string The hash of the text
     * @static
     */
   
public static function hash($string, $raw_output = false)
    {
       
// validate the length of the string
       
if (strlen($string) == 0)
            throw new
HashAlgorithmException("Empty string to hash.");

       
// set the correct raw ouput
       
if (($raw_output !== false) && ($raw_output !== true))
           
$raw_output = false;
       
       
// base function call
       
return sha1($string, $raw_output);
    }
}


?>

For more information send a message to info at phpclasses dot org.