Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Class SecureHash
- {
- private $rawOutput;
- /**
- @usage - boolRawOutput determines whether the hashing functions return raw binary data
- */
- public function __construct($boolRawOutput = false)
- {
- $this -> rawOutput = $boolRawOutput ? true : false;
- }
- /**
- @usage - used to return two 10-byte salts, called internally through the hash functions
- @return - array containing two 10-byte salts
- */
- private function getSalts($intDataLength)
- {
- $dataLength = (int) intval($intDataLength);
- if($dataLength > 40)
- return false;
- $seedbox = array(
- 0xAA . 0x0D . 0x96 . 0xE9 . 0x1A . 0x4B . 0x7D . 0x90 . 0xAB . 0x5E,
- 0xDD . 0x5C . 0x3F . 0x6E . 0x29 . 0x9F . 0x52 . 0xEB . 0xC8 . 0xC2,
- 0xDE . 0x57 . 0x4D . 0xD0 . 0xAE . 0xFC . 0x2C . 0x37 . 0x6F . 0xAA,
- 0xCB . 0xC5 . 0x8A . 0x9B . 0xB4 . 0xB0 . 0x7D . 0x2D . 0x95 . 0xBD,
- 0xC2 . 0xA1 . 0xA5 . 0xDF . 0x8E . 0x12 . 0xF2 . 0xEF . 0x5D . 0x54,
- 0x89 . 0x07 . 0xA8 . 0x10 . 0x1F . 0xCB . 0x3E . 0x73 . 0x3B . 0x74,
- 0xCB . 0xFC . 0xE4 . 0xC3 . 0x56 . 0xE2 . 0x88 . 0x76 . 0x75 . 0x57,
- 0xC7 . 0x5D . 0xB1 . 0x1D . 0x27 . 0x8B . 0x57 . 0x80 . 0x36 . 0xF6,
- 0x36 . 0x8E . 0x12 . 0xD8 . 0x35 . 0xF9 . 0x6A . 0xC9 . 0xE5 . 0x2F,
- 0xB4 . 0x95 . 0x40 . 0x48 . 0x80 . 0x07 . 0x54 . 0x79 . 0xBB . 0xB7,
- 0xC2 . 0x7C . 0x6F . 0x7B . 0xA7 . 0xF2 . 0xE1 . 0x51 . 0xB3 . 0x7F,
- 0xCA . 0xE3 . 0x06 . 0x46 . 0x16 . 0x35 . 0xC2 . 0x42 . 0x29 . 0x2A,
- 0xF9 . 0xA1 . 0x4E . 0x85 . 0xD6 . 0x6C . 0xCB . 0xDC . 0xAA . 0x12,
- 0x1A . 0x26 . 0xC0 . 0x72 . 0x63 . 0x4F . 0x87 . 0x40 . 0xA5 . 0xE6,
- 0xB1 . 0x93 . 0x4A . 0x9A . 0xB1 . 0x8D . 0x27 . 0x26 . 0xBD . 0x53,
- 0xA7 . 0xFD . 0x47 . 0x37 . 0xC2 . 0xAD . 0xA4 . 0xB5 . 0x88 . 0x65,
- 0xF7 . 0xD0 . 0xDC . 0x78 . 0x6F . 0xF0 . 0x6B . 0xBD . 0xA6 . 0x91,
- 0x80 . 0x62 . 0x4A . 0xCF . 0xCA . 0xCA . 0x5B . 0x40 . 0x75 . 0x81,
- 0x0E . 0x59 . 0x3E . 0x5C . 0xCC . 0xCE . 0xCF . 0xA6 . 0x71 . 0xF7,
- 0xD2 . 0x86 . 0x21 . 0xC8 . 0x15 . 0x2D . 0x6D . 0x22 . 0xA4 . 0xD6,
- 0x62 . 0xCB . 0x79 . 0xCE . 0xD1 . 0xD8 . 0x4F . 0xBA . 0xBD . 0x5F,
- 0x5F . 0x0A . 0x7D . 0x5D . 0x6C . 0x84 . 0x11 . 0xCA . 0x65 . 0x52,
- 0xB0 . 0xB3 . 0xCD . 0xFE . 0x2D . 0x21 . 0x28 . 0x6A . 0x06 . 0xF4,
- 0x2B . 0x52 . 0x48 . 0x17 . 0x8D . 0xC9 . 0x96 . 0xF5 . 0x3C . 0x0B,
- 0x65 . 0xC7 . 0x4A . 0xF5 . 0xD0 . 0x67 . 0x83 . 0xB5 . 0x4F . 0x1C,
- 0x5C . 0x8B . 0x1F . 0x72 . 0xB7 . 0xB3 . 0xBE . 0x3B . 0xF5 . 0x18,
- 0x4D . 0x2F . 0xCE . 0x39 . 0x8C . 0xE5 . 0x2A . 0xD5 . 0x34 . 0xFD,
- 0x23 . 0x57 . 0x28 . 0x3F . 0xD3 . 0x38 . 0x55 . 0xEC . 0xD0 . 0x1B,
- 0xFF . 0x1E . 0xD1 . 0x65 . 0x13 . 0x08 . 0x3E . 0x45 . 0x89 . 0xAB,
- 0x70 . 0x06 . 0x2B . 0x86 . 0xED . 0x38 . 0xE3 . 0x7B . 0xE1 . 0x00,
- 0x54 . 0xD0 . 0x34 . 0xD6 . 0x45 . 0x45 . 0x01 . 0x08 . 0xE6 . 0xF2,
- 0xE1 . 0xF8 . 0x4F . 0x96 . 0x08 . 0xDE . 0x3F . 0x2B . 0xAD . 0x2B,
- 0x51 . 0x4A . 0x76 . 0x3D . 0xDC . 0x8E . 0xA4 . 0xDF . 0x4B . 0xFE,
- 0xEB . 0xCD . 0x1A . 0xF5 . 0x2C . 0xE9 . 0xF6 . 0x23 . 0x7E . 0x1C,
- 0xCC . 0xE2 . 0xCE . 0x35 . 0x4A . 0x4A . 0xE4 . 0x89 . 0x79 . 0xDD,
- 0x82 . 0xF4 . 0xF9 . 0x52 . 0x6B . 0xD4 . 0x81 . 0x07 . 0x42 . 0xF6,
- 0x0A . 0x7F . 0x55 . 0x00 . 0xAF . 0x8E . 0xBC . 0xFB . 0xBB . 0x90,
- 0x86 . 0xB2 . 0x28 . 0x42 . 0x4E . 0xB6 . 0x0E . 0xF2 . 0x67 . 0x71,
- 0xA8 . 0xE4 . 0x85 . 0xAE . 0x82 . 0x92 . 0x61 . 0xF7 . 0x0F . 0xC0,
- 0x3E . 0x11 . 0x48 . 0x60 . 0xDD . 0x7D . 0x7D . 0xDC . 0xE5 . 0x10,
- 0xDD . 0xBD . 0x4D . 0x7A . 0x0D . 0xE7 . 0xC0 . 0x1C . 0x36 . 0x85);
- $presalt = $seedbox[$dataLength];
- $postsalt = $seedbox[40 - $dataLength];
- return array($presalt, $postsalt);
- }
- /**
- @usage - used to hash data with two 10-byte salts with support for data lengths from 0-40
- @return - 128-bit, 16-byte or 32 character binary data or string depending on the value of SecureHash::rawOutput
- */
- public function sh_md5($data)
- {
- if($salt_data = $this -> getSalts(strlen($data)))
- {
- list($presalt, $postsalt) = $salt_data;
- return md5($presalt . $data . $postsalt, $this -> rawOutput);
- }
- return false;
- }
- /**
- @usage - used to hash data with two 10-byte salts with support for data lengths from 0-40
- @return - 160-bit, 20-byte or 40 character binary data or string depending on the value of SecureHash::rawOutput
- */
- public function sh_sha1($data)
- {
- if($salt_data = $this -> getSalts(strlen($data)))
- {
- list($presalt, $postsalt) = $salt_data;
- return sha1($presalt . $data . $postsalt, $this -> rawOutput);
- }
- return false;
- }
- /**
- @usage - used to hash data with two 10-byte salts with support for data lengths from 0-40
- @return - 224-bit, 28-byte or 56 character binary data or string depending on the value of SecureHash::rawOutput
- @requires - usage of this function requires MHASH be installed in your php version, this extension is usually included with mcrypt.
- */
- public function sh_sha224($data)
- {
- if($salt_data = $this -> getSalts(strlen($data)))
- {
- list($presalt, $postsalt) = $salt_data;
- return $this -> rawOutput ? mhash(MHASH_SHA224, $presalt . $data . $postsalt) : bin2hex(mhash(MHASH_SHA224, $presalt . $data . $postsalt));
- }
- return false;
- }
- /**
- @usage - used to hash data with two 10-byte salts with support for data lengths from 0-40
- @return - 256-bit, 32-byte or 64 character binary data or string depending on the value of SecureHash::rawOutput
- @requires - usage of this function requires MHASH be installed in your php version, this extension is usually included with mcrypt.
- */
- public function sh_sha256($data)
- {
- if($salt_data = $this -> getSalts(strlen($data)))
- {
- list($presalt, $postsalt) = $salt_data;
- return $this -> rawOutput ? mhash(MHASH_SHA256, $presalt . $data . $postsalt) : bin2hex(mhash(MHASH_SHA256, $presalt . $data . $postsalt));
- }
- }
- /**
- @usage - used to hash data with two 10-byte salts with support for data lengths from 0-40
- @return - 384-bit, 48-byte or 96 character binary data or string depending on the value of SecureHash::rawOutput
- @requires - usage of this function requires MHASH be installed in your php version, this extension is usually included with mcrypt.
- */
- public function sh_sha384($data)
- {
- if($salt_data = $this -> getSalts(strlen($data)))
- {
- list($presalt, $postsalt) = $salt_data;
- return $this -> rawOutput ? mhash(MHASH_SHA384, $presalt . $data . $postsalt) : bin2hex(mhash(MHASH_SHA384, $presalt . $data . $postsalt));
- }
- }
- /**
- @usage - used to hash data with two 10-byte salts with support for data lengths from 0-40
- @return - 512-bit, 64-byte or 128 character binary data or string depending on the value of SecureHash::rawOutput
- @requires - usage of this function requires MHASH be installed in your php version, this extension is usually included with mcrypt.
- */
- public function sh_sha512($data)
- {
- if($salt_data = $this -> getSalts(strlen($data)))
- {
- list($presalt, $postsalt) = $salt_data;
- return $this -> rawOutput ? mhash(MHASH_SHA512, $presalt . $data . $postsalt) : bin2hex(mhash(MHASH_SHA512, $presalt . $data . $postsalt));
- }
- }
- /**
- @usage - used to hash data with two 10-byte salts with support for data lengths from 0-40
- @return - 160-bit, 20-byte or 40-character binary data or string depending on the value of SecureHash::rawOutput
- @requires - usage of this function requires MHASH be installed in your php version, this extension is usually included with mcrypt.
- */
- public function sh_tiger($data)
- {
- if($salt_data = $this -> getSalts(strlen($data)))
- {
- list($presalt, $postsalt) = $salt_data;
- return $this -> rawOutput ? mhash(MHASH_TIGER, $presalt . $data . $postsalt) : bin2hex(mhash(MHASH_TIGER, $presalt . $data . $postsalt));
- }
- }
- /**
- @usage - used to hash data with two 10-byte salts with support for data lengths from 0-40
- @return - 512-bit, 64-byte or 128-character binary data or string depending on the value of SecureHash::rawOutput
- @requires - usage of this function requires MHASH be installed in your php version, this extension is usually included with mcrypt.
- */
- public function sh_whirlpool($data)
- {
- if($salt_data = $this -> getSalts(strlen($data)))
- {
- list($presalt, $postsalt) = $salt_data;
- return $this -> rawOutput ? mhash(MHASH_WHIRLPOOL, $presalt . $data . $postsalt) : bin2hex(mhash(MHASH_WHIRLPOOL, $presalt . $data . $postsalt));
- }
- }
- /**
- @usage - used to hash data with two 10-byte salts with support for data lengths from 0-40
- @return - 256-bit, 32-byte or 64-character binary data or string depending on the value of SecureHash::rawOutput
- @requires - usage of this function requires MHASH be installed in your php version, this extension is usually included with mcrypt.
- */
- public function sh_gost($data)
- {
- if($salt_data = $this -> getSalts(strlen($data)))
- {
- list($presalt, $postsalt) = $salt_data;
- return $this -> rawOutput ? mhash(MHASH_GOST, $presalt . $data . $postsalt) : bin2hex(mhash(MHASH_GOST, $presalt . $data . $postsalt));
- }
- }
- }
- $SecureHash= new SecureHash(false);
- $hash_string = $SecureHash -> sh_gost('teststring');
- echo $hash_string;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement