Exemple #1
0
 function __signature($amount, $order, $code, $currency, $clave)
 {
     $sha = new SHA();
     $message = $amount . $order . $code . $currency . $clave;
     $digest1 = $sha->hash_string($message);
     $signature = strtoupper($sha->hash_to_string($digest1));
     return $signature;
 }
Exemple #2
0
 /**
  * @brief Get the object's cached SHA-1 hash value.
  *
  * @returns (SHA) The hash value (binary sha1).
  */
 public function getSha()
 {
     if (is_null($this->sha)) {
         $data = $this->serialize();
         $this->sha = SHA::hash(sprintf("%s %d%s", $this->getTypeName(), strlen($data), $data));
     }
     return $this->sha;
 }
 function hash($str)
 {
     global $PREFS;
     if ($PREFS->ini('encryption_type') == 'md5') {
         return md5($str);
     }
     if (!function_exists('sha1')) {
         if (!function_exists('mhash')) {
             if (!class_exists('SHA')) {
                 require PATH_CORE . 'core.sha1' . EXT;
             }
             $SH = new SHA();
             return $SH->encode_hash($str);
         } else {
             return bin2hex(mhash(MHASH_SHA1, $str));
         }
     } else {
         return sha1($str);
     }
 }
 public function after_extern_process()
 {
     global $temp_orders_id;
     if (isset($_GET['SHASIGN'])) {
         include DIR_WS_CLASSES . 'sha.php';
         $get_params = array();
         foreach ($_GET as $key => $value) {
             if ($key != 'SHASIGN' && $key != 'force_checkout_step' && $key != 'customer_id' && $key != 'osCsid' && trim($value) != '') {
                 $get_params[strtoupper($key)] = $value;
             }
         }
         ksort($get_params);
         $temp_data = Checkout::get_all_data_from_temp_db($temp_orders_id);
         $hash_string = '';
         foreach ($get_params as $key => $value) {
             $hash_string .= strtoupper($key) . '=' . $value . $this->instances[$temp_data[$temp_orders_id]['orders']['payment_method']]['sha_string'];
         }
         $sha = new SHA();
         $hasharray = $sha->hash_string($hash_string);
         $hash = strtoupper($sha->hash_to_string($hasharray));
         if ($_GET['SHASIGN'] != $hash) {
             //wrong ogone parameters
             $this->errors[$temp_data[$temp_orders_id]['orders']['payment_method']] = Translate('Er is iets fout gelopen bij de afhandeling van uw betaling. Contacteer ons voor meer uitleg.');
         }
         $_GET['force_checkout_step'] = Checkout::get_step_for_type($this->type);
         $_POST['checkout_step'] = Checkout::last_active_step();
     }
     return;
 }
Exemple #5
0
	/**
	 * Generate an SHA1 Hash
	 *
	 * @access	public
	 * @param	string
	 * @return	string
	 */
	function sha1($str)
	{
		if ( ! function_exists('sha1'))
		{
			if ( ! function_exists('mhash'))
			{
				require_once(BASEPATH.'libraries/Sha1'.EXT);
				$SH = new SHA;
				return $SH->generate($str);
			}
			else
			{
				return bin2hex(mhash(MHASH_SHA1, $str));
			}
		}
		else
		{
			return sha1($str);
		}
	}
 function sha1($str)
 {
     if (!function_exists('sha1')) {
         if (!function_exists('mhash')) {
             $SH = new SHA();
             return $SH->generate($str);
         } else {
             return bin2hex(mhash(MHASH_SHA1, $str));
         }
     } else {
         return sha1($str);
     }
 }
Exemple #7
0
<?php

require_once dirname(__FILE__) . '/../bootstrap/unit.php';
$t = new lime_test(9, new lime_output_color());
$quick = "The quick brown fox jumped over the lazy dog";
$t->comment('Testing SHA::hash()');
$h = SHA::hash($quick);
$t->is($h->hex(), 'f6513640f3045e9768b239785625caa6a2588842', '->hex() returns hash');
$t->is($h->h(), 'f6513640f3045e9768b239785625caa6a2588842', '->h() returns hash');
$t->is($h->bin(), pack('H40', 'f6513640f3045e9768b239785625caa6a2588842'), '->bin() returns binary hash');
$t->is($h->b(), pack('H40', 'f6513640f3045e9768b239785625caa6a2588842'), '->b() returns binary hash');
$t->is((string) $h, pack('H40', 'f6513640f3045e9768b239785625caa6a2588842'), '__toString() returns binary hash');
$t->comment('Testing constructor');
$h = new SHA(pack('H40', 'f6513640f3045e9768b239785625caa6a2588842'));
$t->is((string) $h, pack('H40', 'f6513640f3045e9768b239785625caa6a2588842'), 'constructor accepts bin string');
$h = new SHA('f6513640f3045e9768b239785625caa6a2588842');
$t->is((string) $h, pack('H40', 'f6513640f3045e9768b239785625caa6a2588842'), 'constructor accepts hex string');
try {
    $h = new SHA($quick);
    $t->fail('no code after exception on line ' . __LINE__);
} catch (Exception $e) {
    $t->pass('Constructor throws an exception on random string');
}
try {
    $h = new SHA('q6513640f3045e9768b239785625caa6a2588842');
    $t->fail('no code after exception on line ' . __LINE__);
} catch (Exception $e) {
    $t->pass('Constructor throws an exception on string looking like a hex code');
}
Exemple #8
0
 /**
  * @brief Fetch an object in its binary representation by name.
  *
  * Throws an exception if the object cannot be found.
  *
  * @param $object_name (string) name of the object (binary SHA1)
  * @return (array) an array consisting of the object type name (string) and the
  * binary representation of the object (string)
  */
 public function getRawObject(SHA $sha)
 {
     static $cache = array();
     /* FIXME allow limiting the cache to a certain size */
     if (!isset($cache[(string) $sha])) {
         $path = sprintf('%s/objects/%s/%s', $this->dir, substr($sha->hex(), 0, 2), substr($sha->hex(), 2));
         if (file_exists($path)) {
             list($hdr, $object_data) = explode("", gzuncompress(file_get_contents($path)), 2);
             sscanf($hdr, "%s %d", $type, $object_size);
             $cache[(string) $sha] = array($type, $object_data);
         } else {
             if ($x = $this->findPackedObject($sha)) {
                 list($pack_sha, $object_offset) = $x;
                 $pack = fopen(sprintf('%s/objects/pack/pack-%s.pack', $this->dir, $pack_sha->hex()), 'rb');
                 flock($pack, LOCK_SH);
                 /* check magic and version */
                 $magic = fread($pack, 4);
                 $version = Binary::fuint32($pack);
                 if ($magic != 'PACK' || $version != 2) {
                     throw new Exception('unsupported pack format');
                 }
                 $cache[(string) $sha] = $this->unpackObject($pack, $object_offset);
                 fclose($pack);
             } else {
                 throw new Exception(sprintf('object not found: %s', $sha->hex()));
             }
         }
     }
     return $cache[(string) $sha];
 }