3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pubkey = '...public key here...'; $privkey = '...private key here...'; function encrypt($data) { global $pubkey, $privkey; if (openssl_public_encrypt($data, $encrypted, $pubkey)) $data = base64_encode($encrypted); else throw new Exception('Unable to encrypt data. Perhaps it is bigger than the key size?'); return $data; } function decrypt($data) { global $pubkey, $privkey; if (openssl_private_decrypt(base64_decode($data), $decrypted, $privkey)) $data = $decrypted; else $data = ''; return $data; } $e = encrypt('hello'); var_dump($e); var_dump(decrypt($e));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QQKdm
function name:  (null)
number of ops:  16
compiled vars:  !0 = $pubkey, !1 = $privkey, !2 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '...public+key+here...'
    4     1        ASSIGN                                                   !1, '...private+key+here...'
   28     2        INIT_FCALL                                               'encrypt'
          3        SEND_VAL                                                 'hello'
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !2, $5
   29     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                                 
   30     9        INIT_FCALL                                               'var_dump'
         10        INIT_FCALL                                               'decrypt'
         11        SEND_VAR                                                 !2
         12        DO_FCALL                                      0  $8      
         13        SEND_VAR                                                 $8
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Function encrypt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/QQKdm
function name:  encrypt
number of ops:  20
compiled vars:  !0 = $data, !1 = $pubkey, !2 = $privkey, !3 = $encrypted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        BIND_GLOBAL                                              !1, 'pubkey'
          2        BIND_GLOBAL                                              !2, 'privkey'
    9     3        INIT_FCALL_BY_NAME                                       'openssl_public_encrypt'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !3
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $4      
          8      > JMPZ                                                     $4, ->14
   10     9    >   INIT_FCALL                                               'base64_encode'
         10        SEND_VAR                                                 !3
         11        DO_ICALL                                         $5      
         12        ASSIGN                                                   !0, $5
         13      > JMP                                                      ->18
   12    14    >   NEW                                              $7      'Exception'
         15        SEND_VAL_EX                                              'Unable+to+encrypt+data.+Perhaps+it+is+bigger+than+the+key+size%3F'
         16        DO_FCALL                                      0          
         17      > THROW                                         0          $7
   14    18    > > RETURN                                                   !0
   15    19*     > RETURN                                                   null

End of function encrypt

Function decrypt:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QQKdm
function name:  decrypt
number of ops:  17
compiled vars:  !0 = $data, !1 = $pubkey, !2 = $privkey, !3 = $decrypted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        BIND_GLOBAL                                              !1, 'pubkey'
          2        BIND_GLOBAL                                              !2, 'privkey'
   20     3        INIT_FCALL_BY_NAME                                       'openssl_private_decrypt'
          4        INIT_FCALL                                               'base64_decode'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $4      
          7        SEND_VAR_NO_REF_EX                                       $4
          8        SEND_VAR_EX                                              !3
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0  $5      
         11      > JMPZ                                                     $5, ->14
   21    12    >   ASSIGN                                                   !0, !3
         13      > JMP                                                      ->15
   23    14    >   ASSIGN                                                   !0, ''
   25    15    > > RETURN                                                   !0
   26    16*     > RETURN                                                   null

End of function decrypt

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
230 ms | 1407 KiB | 21 Q