Jump to content

sha1 hashing goes wrong


Dok1508

Recommended Posts

Hello all,

 

I looked everytwhere to find the answer to my question bug so far, no luck. I hope someone here can help me with this issue.

 

Oke, my problem is as following.

 

I'm creating a string with a foreach loop that I then will has after the loop. The problem is, is that that string is addad to a variable. When I sha1 hash that variable with the sha1 function from within PHP I get a different hash as when I just echo the string and manually hash that.

 

The point is, is that the manually hashed string is then correct, and the automitically hash string isn't.

 

This is the code I'm using, can someone tell me where to look at to solve this problem?

 

if (is_array($this->getFormData())){
    			foreach ($this->getFormData() as $name => $value) { 
        			$string .= $name."=".$value.$shamethod;
  				}
		}
		$hashstring = sha1($string, false);
		echo '<br /><br />'.$hashstring.'<br /><br />';
		echo $string;

 

Thanks for  your time.

 

Dok

Link to comment
Share on other sites

Hello simshaun,

 

Thanks for your reply.

 

I copied string into dreamweaver to make sure no whitespace was added. Afther that I manually hashed it with an online sha1 generator. The generated sha string is then the correct one. So it looks like hashing the variable containing the string just goes wrong somehow. I really don't get this one.

 

Link to comment
Share on other sites

Maybe the complete code blok may help

 

<?php 
 if (is_array($this->getFormData())){?>
        <?php foreach ($this->getFormData() as $name => $value) { ?>
            <input type="hidden" name="<?php echo($name); ?>" value="<?php echo($value); ?>" />
        <?php }
     }
$sha = $this->_getApi()->getConfig()->getSHA();
if ($sha == "NEW"){
	$shamethod = $this->getShaCode();
	if (is_array($this->getFormData())){
    		foreach ($this->getFormData() as $name => $value) { 
        		$string .= $name.'='.$value.$shamethod;
  			}
	}
	$hashstring = sha1($string, false);
	echo '<br /><br />'.$hashstring.'<br /><br />';
	echo $string;
	?><input type="hidden" name="SHASIGN" value="<?php echo $hashstring; ?>" /><?php
	}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.