I am getting two different hash values when line breaks are added.
On this site http://www.xorbin.com/tools/sha256-hash-calculator there is a JavaScript Sha256 hash generator.
When I run a hash on "onetwo" I get:
25b6746d5172ed6352966a013d93ac846e1110d5a25e8f183b5931f4688842a1
When I use PHP
echo hash('sha256', 'onetwo');
I get:
25b6746d5172ed6352966a013d93ac846e1110d5a25e8f183b5931f4688842a1
But when I run a hash from the URL that includes a line break (return) like:
'one
two'
I get:
21066d108d5319ecb5a1fc4454f42ef22fc5f1c7df49c31d90294950e0ea8b2c
But when I use PHP I get:
29a776bb35efe730dabb1b1d3ad74dbf80cc3e9009e168241798ea73adca3dcf
Can any one point out why this is so? Why does adding line breaks give different results?
Here is my PHP/HTML code as you will see I am using a form and submitting the data to be hashed.
<!DOCTYPE HTML>
<html>
<head>
<title>Sha256 Hash</title>
</head>
<body>
<div style="float: left;">
Start here and insert text below to be hashed.<br />
<form name="submit hash" action="" method="POST">
<textarea name="text" style="border: thin solid #000; width: 500px; padding: 10px; height: 500px;"><? if($_SERVER['REQUEST_METHOD'] == 'POST') echo $_POST['text']; ?></textarea>
<br style="clear: both;" />
<input type="submit" name="submit" value="submit" />
</form>
</div>
<? if($_SERVER['REQUEST_METHOD'] == 'POST'): ?>
<div style="border: thin solid #000; margin: 10px; padding: 10px; float: left;">
<br />sha256: <b><?= hash('sha256',$_POST['text']); ?></b><br />
</div>
<? endif; ?>
</body>
</html>
<? ... ?>) as their use is discouraged for portability reasons, see php.net/manual/en/language.basic-syntax.phptags.php - Steve Wilford