3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CRYPTO{ const TZ = 'UTC'; const TIMEFRAME = 100; const TIME = 'H:i:s'; public static function ver($data, $signature, $privateKey, $timestamp){ $now = self::timestamp(self::TZ); $tmin = ( $now - ( self::TIMEFRAME/2 ) ); $tmax = ( $now + ( self::TIMEFRAME/2 ) ); if( ($tmin>$tmax ) or ( $tmin<$tmax ) ) return false; //out of time range $data = strval( $data ); $computed_sig = self::signature($data, $privateKey, $timestamp); return $signature == $computed_sig; } public static function sign($data, $privateKey, $timestamp=null){ $timestamp = empty($timestamp) ? self::timestamp(self::TZ) : intval($timestamp); $data = strval( $data ); $sig = base64_encode( hash_hmac("sha256", $data, $privateKey . '-' . date(self::TIME, $timestamp), true) ); echo "Time: " . $timestamp; return $sig; } public static function timestamp($tz='GTM'){ $tz = new \DateTimeZone($tz); return date_create(NULL, $tz)->getTimestamp(); } public static function isValid($algo){ $algos = hash_algos(); return in_array($algo, $algos); } } date_default_timezone_set('UTC'); $timestamp = empty($timestamp) ? CRYPTO::timestamp(CRYPTO::TZ) : intval($timestamp); $success_url = "https://www.google.si/search?q=succesds"; $url = urlencode($success_url); echo " URL: " . $url; echo " Signature: " . CRYPTO::sign( $url, 'sddfdffddffddpodaosa', $timestamp);

preferences:
56.83 ms | 402 KiB | 5 Q