简体   繁体   English

验证sha256哈希

[英]Verify sha256 hash

I am trying to verify that this hash was not messed with, and use the time stamp to do so. 我正在尝试验证此哈希没有被弄乱,并使用时间戳来做到这一点。 I know there is no way to reverse a hash without brute force. 我知道没有蛮力就无法扭转哈希。 How would I be able to verify it at a later date? 我以后如何验证?

Is there a php code I dont know about? 有我不知道的PHP代码吗?

Please and thank you. 谢谢,麻烦您了。

$log = fopen($datalog, 'a') or die("can't open file");

echo " ";
echo "IP: ";
echo $address;
$addressHash = hash_hmac('sha256', $address,  $key);
$add64 = base64_encode($addressHash);
fwrite ($log, $add64);
echo " ";
echo "INFO: ";
echo $info;
$infoHash = hash_hmac('sha256', $info,  $key);
$info64 = base64_encode($infoHash);
fwrite ($log, $info64);
echo " ";
echo "TIMESTAMP: ";
echo $datetimeStamp;
$tsHash = hash_hmac('sha256', $datetimeStamp,  $key);
$ts64 = base64_encode($tsHash);
fwrite ($log, $ts64);
echo " ";
echo "COUNTRY: ";
echo $country;
$countryHash = hash_hmac('sha256', $country,  $key);
$country64 = base64_encode($countryHash);
fwrite ($log, $country64);
echo " ";
echo "LATITUDE: ";
echo $lat;
$latHash = hash_hmac('sha256', $lat,  $key);
$lat64 = base64_encode($latHash);
fwrite ($log, $lat64);
echo " ";
echo "LONGITUDE: ";
echo $long;
$longHash = hash_hmac('sha256', $long,  $key);
$long64 = base64_encode($longHash);
fwrite ($log, $long64);

fclose($log);

}

Generate the string you think php is hashing and pass it to a different sha256 calculator to compare the results. 生成您认为php正在哈希的字符串,并将其传递给其他sha256计算器以比较结果。 There are online calculators - just google sha256 online to get one. 有在线计算器-只需sha256 online使用Google sha256 online即可。 Alternatively, on linux/OSX there is a terminal sha256 calculator ( sha256sum on my linux). 另外,在linux / OSX上,有一个终端sha256计算器(在我的linux上是sha256sum )。 It could be used in the terminal as follows: 可以在终端中使用它,如下所示:

echo "string to sha" | sha256sum

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM