3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('SECRET', 'private-key'); $payload = [ "id" => 1, "username" => "test@example.com", "created_at" => "2018-10-11 13:30:29", "updated_at" => "2018-10-17 11:17:14" ]; echo verifySignature(SECRET, 'https://example.com/webhook', $payload, 1517949000); function verifySignature(string $secret, string $webhookUrl, array $payload, int $timestamp): string { $jsonPayload = json_encode($payload); $stringToSign = "NORDWL-HMAC-SHA256\n"; $stringToSign .= sprintf("Timestamp %d\n", $timestamp); $stringToSign .= hash('sha256', $jsonPayload); $timestampKey = hash_hmac('sha256', $timestamp, 'NORDWL' . $secret, true); $signingKey = hash_hmac('sha256', $webhookUrl, $timestampKey, true); return hash_hmac('sha256', $stringToSign, $signingKey); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1rvX5
function name:  (null)
number of ops:  14
compiled vars:  !0 = $payload
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'SECRET'
          2        SEND_VAL                                                 'private-key'
          3        DO_ICALL                                                 
    5     4        ASSIGN                                                   !0, <array>
   12     5        INIT_FCALL_BY_NAME                                       'verifySignature'
          6        FETCH_CONSTANT                                   ~3      'SECRET'
          7        SEND_VAL_EX                                              ~3
          8        SEND_VAL_EX                                              'https%3A%2F%2Fexample.com%2Fwebhook'
          9        SEND_VAR_EX                                              !0
         10        SEND_VAL_EX                                              1517949000
         11        DO_FCALL                                      0  $4      
         12        ECHO                                                     $4
   26    13      > RETURN                                                   1

Function verifysignature:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1rvX5
function name:  verifySignature
number of ops:  43
compiled vars:  !0 = $secret, !1 = $webhookUrl, !2 = $payload, !3 = $timestamp, !4 = $jsonPayload, !5 = $stringToSign, !6 = $timestampKey, !7 = $signingKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   16     4        INIT_FCALL                                               'json_encode'
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $8      
          7        ASSIGN                                                   !4, $8
   18     8        ASSIGN                                                   !5, 'NORDWL-HMAC-SHA256%0A'
   19     9        INIT_FCALL                                               'sprintf'
         10        SEND_VAL                                                 'Timestamp+%25d%0A'
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $11     
         13        ASSIGN_OP                                     8          !5, $11
   20    14        INIT_FCALL                                               'hash'
         15        SEND_VAL                                                 'sha256'
         16        SEND_VAR                                                 !4
         17        DO_ICALL                                         $13     
         18        ASSIGN_OP                                     8          !5, $13
   22    19        INIT_FCALL                                               'hash_hmac'
         20        SEND_VAL                                                 'sha256'
         21        SEND_VAR                                                 !3
         22        CONCAT                                           ~15     'NORDWL', !0
         23        SEND_VAL                                                 ~15
         24        SEND_VAL                                                 <true>
         25        DO_ICALL                                         $16     
         26        ASSIGN                                                   !6, $16
   23    27        INIT_FCALL                                               'hash_hmac'
         28        SEND_VAL                                                 'sha256'
         29        SEND_VAR                                                 !1
         30        SEND_VAR                                                 !6
         31        SEND_VAL                                                 <true>
         32        DO_ICALL                                         $18     
         33        ASSIGN                                                   !7, $18
   25    34        INIT_FCALL                                               'hash_hmac'
         35        SEND_VAL                                                 'sha256'
         36        SEND_VAR                                                 !5
         37        SEND_VAR                                                 !7
         38        DO_ICALL                                         $20     
         39        VERIFY_RETURN_TYPE                                       $20
         40      > RETURN                                                   $20
   26    41*       VERIFY_RETURN_TYPE                                       
         42*     > RETURN                                                   null

End of function verifysignature

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.81 ms | 1400 KiB | 23 Q