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=sucasasascesds"; $url = urlencode($success_url); echo " URL: " . $url; echo " Signature: " . CRYPTO::sign( $url, 'sdsadass42323daddpodaoppsdaosa', $timestamp);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fstVq
function name:  (null)
number of ops:  28
compiled vars:  !0 = $timestamp, !1 = $success_url, !2 = $url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   INIT_FCALL                                               'date_default_timezone_set'
          1        SEND_VAL                                                 'UTC'
          2        DO_ICALL                                                 
   38     3        ISSET_ISEMPTY_CV                                         !0
          4      > JMPZ                                                     ~4, ->10
          5    >   INIT_STATIC_METHOD_CALL                                  'CRYPTO', 'timestamp'
          6        SEND_VAL                                                 'UTC'
          7        DO_FCALL                                      0  $5      
          8        QM_ASSIGN                                        ~6      $5
          9      > JMP                                                      ->12
         10    >   CAST                                          4  ~7      !0
         11        QM_ASSIGN                                        ~6      ~7
         12    >   ASSIGN                                                   !0, ~6
   40    13        ASSIGN                                                   !1, 'https%3A%2F%2Fwww.google.si%2Fsearch%3Fq%3Dsucasasascesds'
   42    14        INIT_FCALL                                               'urlencode'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $10     
         17        ASSIGN                                                   !2, $10
   44    18        CONCAT                                           ~12     '+URL%3A+', !2
         19        ECHO                                                     ~12
   45    20        INIT_STATIC_METHOD_CALL                                  'CRYPTO', 'sign'
         21        SEND_VAR                                                 !2
         22        SEND_VAL                                                 'sdsadass42323daddpodaoppsdaosa'
         23        SEND_VAR                                                 !0
         24        DO_FCALL                                      0  $13     
         25        CONCAT                                           ~14     '+Signature%3A+', $13
         26        ECHO                                                     ~14
         27      > RETURN                                                   1

Class CRYPTO:
Function ver:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/fstVq
function name:  ver
number of ops:  29
compiled vars:  !0 = $data, !1 = $signature, !2 = $privateKey, !3 = $timestamp, !4 = $now, !5 = $tmin, !6 = $tmax, !7 = $computed_sig
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    7     4        INIT_STATIC_METHOD_CALL                                  'timestamp'
          5        SEND_VAL_EX                                              'UTC'
          6        DO_FCALL                                      0  $8      
          7        ASSIGN                                                   !4, $8
    8     8        SUB                                              ~10     !4, 50
          9        ASSIGN                                                   !5, ~10
    9    10        ADD                                              ~12     !4, 50
         11        ASSIGN                                                   !6, ~12
   11    12        IS_SMALLER                                       ~14     !6, !5
         13      > JMPNZ_EX                                         ~14     ~14, ->16
         14    >   IS_SMALLER                                       ~15     !5, !6
         15        BOOL                                             ~14     ~15
         16    > > JMPZ                                                     ~14, ->18
   12    17    > > RETURN                                                   <false>
   14    18    >   CAST                                          6  ~16     !0
         19        ASSIGN                                                   !0, ~16
   15    20        INIT_STATIC_METHOD_CALL                                  'signature'
         21        SEND_VAR_EX                                              !0
         22        SEND_VAR_EX                                              !2
         23        SEND_VAR_EX                                              !3
         24        DO_FCALL                                      0  $18     
         25        ASSIGN                                                   !7, $18
   16    26        IS_EQUAL                                         ~20     !1, !7
         27      > RETURN                                                   ~20
   18    28*     > RETURN                                                   null

End of function ver

Function sign:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fstVq
function name:  sign
number of ops:  35
compiled vars:  !0 = $data, !1 = $privateKey, !2 = $timestamp, !3 = $sig
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   21     3        ISSET_ISEMPTY_CV                                         !2
          4      > JMPZ                                                     ~4, ->10
          5    >   INIT_STATIC_METHOD_CALL                                  'timestamp'
          6        SEND_VAL_EX                                              'UTC'
          7        DO_FCALL                                      0  $5      
          8        QM_ASSIGN                                        ~6      $5
          9      > JMP                                                      ->12
         10    >   CAST                                          4  ~7      !2
         11        QM_ASSIGN                                        ~6      ~7
         12    >   ASSIGN                                                   !2, ~6
   22    13        CAST                                          6  ~9      !0
         14        ASSIGN                                                   !0, ~9
   24    15        INIT_FCALL                                               'base64_encode'
         16        INIT_FCALL                                               'hash_hmac'
         17        SEND_VAL                                                 'sha256'
         18        SEND_VAR                                                 !0
         19        CONCAT                                           ~11     !1, '-'
         20        INIT_FCALL                                               'date'
         21        SEND_VAL                                                 'H%3Ai%3As'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                         $12     
         24        CONCAT                                           ~13     ~11, $12
         25        SEND_VAL                                                 ~13
         26        SEND_VAL                                                 <true>
         27        DO_ICALL                                         $14     
         28        SEND_VAR                                                 $14
         29        DO_ICALL                                         $15     
         30        ASSIGN                                                   !3, $15
   25    31        CONCAT                                           ~17     'Time%3A+', !2
         32        ECHO                                                     ~17
   26    33      > RETURN                                                   !3
   28    34*     > RETURN                                                   null

End of function sign

Function timestamp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fstVq
function name:  timestamp
number of ops:  13
compiled vars:  !0 = $tz
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV_INIT                                        !0      'GTM'
   31     1        NEW                                              $1      'DateTimeZone'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
          5        INIT_FCALL                                               'date_create'
          6        SEND_VAL                                                 null
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $4      
          9        INIT_METHOD_CALL                                         $4, 'getTimestamp'
         10        DO_FCALL                                      0  $5      
         11      > RETURN                                                   $5
   32    12*     > RETURN                                                   null

End of function timestamp

Function isvalid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fstVq
function name:  isValid
number of ops:  10
compiled vars:  !0 = $algo, !1 = $algos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        INIT_FCALL                                               'hash_algos'
          2        DO_ICALL                                         $2      
          3        ASSIGN                                                   !1, $2
          4        INIT_FCALL                                               'in_array'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $4      
          8      > RETURN                                                   $4
   35     9*     > RETURN                                                   null

End of function isvalid

End of class CRYPTO.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.66 ms | 1408 KiB | 29 Q