Dok1508 Posted November 10, 2010 Share Posted November 10, 2010 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 Quote Link to comment Share on other sites More sharing options...
simshaun Posted November 10, 2010 Share Posted November 10, 2010 When you are highlighting the output from $string, are you sure its not picking up an extra space or anything as is typical for browsers to do? Copy/paste it into notepad and be sure there are no extra spaces tacked on to the end before you manually hash it. Quote Link to comment Share on other sites More sharing options...
Dok1508 Posted November 10, 2010 Author Share Posted November 10, 2010 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. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 10, 2010 Share Posted November 10, 2010 Quick question: are you going for HMAC? Quote Link to comment Share on other sites More sharing options...
Dok1508 Posted November 10, 2010 Author Share Posted November 10, 2010 Hello Requinix, Thanks for you reply, Its a HMAC based setup. The server where this sha string is posted to will hash the posted variable again with the provided key. Quote Link to comment Share on other sites More sharing options...
Dok1508 Posted November 10, 2010 Author Share Posted November 10, 2010 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 } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.