简体   繁体   中英

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?

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. There are online calculators - just google sha256 online to get one. Alternatively, on linux/OSX there is a terminal sha256 calculator ( sha256sum on my linux). It could be used in the terminal as follows:

echo "string to sha" | sha256sum

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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