3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function encrypt($key, $data){ $b = mcrypt_get_block_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $enc = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($enc), MCRYPT_DEV_URANDOM); mcrypt_generic_init($enc, md5($key), $iv); // PKCS7 Padding from: https://gist.github.com/1077723 $dataPad = $b-(strlen($data)%$b); $data .= str_repeat(chr($dataPad), $dataPad); $encrypted_data = mcrypt_generic($enc, $data); mcrypt_generic_deinit($enc); mcrypt_module_close($enc); return array( 'data' => base64_encode($encrypted_data), 'iv' => base64_encode($iv) ); } function decrypt($key, $iv, $encryptedData){ $iv = base64_decode($iv); $enc = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, ''); mcrypt_generic_init($enc, md5($key), $iv); $encryptedData = base64_decode($encryptedData); $data = mdecrypt_generic($enc, $encryptedData); mcrypt_generic_deinit($enc); mcrypt_module_close($enc); // PKCS7 Padding from: https://gist.github.com/1077723 $dataPad = ord($data[strlen($data)-1]); return substr($data, 0, -$dataPad); } $data = 'Hello world!'; $key = '1234567890'; $enc = encrypt($key, $data); echo "Encrypted: '{$enc['data']}'\n"; $dec = decrypt($key, $enc['iv'], $enc['data']); echo "Decrypted: '$dec'";
Output for 7.0.6 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function mcrypt_get_block_size() in /in/XKTd2:3 Stack trace: #0 /in/XKTd2(42): encrypt('1234567890', 'Hello world!') #1 {main} thrown in /in/XKTd2 on line 3
Process exited with code 255.
Output for 7.0.5
Encrypted: 'DH58CAGNrJ/wAzhpPMte+4D8G5fD+uDGRXQeKRFNS2s=' Decrypted: 'Hello world!'
Output for 7.0.4
Encrypted: 'd7eM3vN3gzUTiJLnm7YIZmnhsMjyABLOguML+hOwZW0=' Decrypted: 'Hello world!'
Output for 7.0.3
Encrypted: 'BX0skvPy8JotsBdkF2ooYJQOvvEe8VVcDG6tQet3KRg=' Decrypted: 'Hello world!'
Output for 7.0.2
Encrypted: 't2b0UclnPLAGjzNKjSOGH3iHqVuoDg6mdp0Gu8CRDI4=' Decrypted: 'Hello world!'
Output for 7.0.1
Encrypted: '7kNoPEEnOpC384nbP7ke2/T9Uf+SCDQ+oJlUwEfpqt0=' Decrypted: 'Hello world!'
Output for 7.0.0
Encrypted: 'MknNEJWviogIjJkmDkHLbZPKyttD8kIsqYobEK6kQOY=' Decrypted: 'Hello world!'
Output for hhvm-3.12.0
Encrypted: 'IEJME550eV0NxCfiul6O1dTrG6sSC1BH+5MeoOv6258=' Decrypted: 'Hello world!'
Output for hhvm-3.10.0
Encrypted: 'k5XL2Cd/RN6Bln8PIkWfxQEwkCJkdyAgraFQLcS0rsI=' Decrypted: 'Hello world!'
Output for 5.0.0 - 5.4.35, 5.5.35, 5.6.21 - 5.6.28
Fatal error: Call to undefined function mcrypt_get_block_size() in /in/XKTd2 on line 3
Process exited with code 255.
Output for 5.6.20
Encrypted: 'MmKfy9rXZbUQ6605KoJB9e5WntqvDecGx+bfMwU/FzE=' Decrypted: 'Hello world!'
Output for 5.6.19
Encrypted: 'w5rDPx8NIepmvDT09LBvPxm/xsAQAzQAok4Rx7aWmQQ=' Decrypted: 'Hello world!'
Output for 5.6.18
Encrypted: 'zHF/4//4JuGHb6B7bHjHzZzzRj8J+V+c2q80qNRJOp4=' Decrypted: 'Hello world!'
Output for 5.6.17
Encrypted: 'b6t4RJeBS+gJubSaHkfTBJEJiRxf5WWRc0gl6n7EGYM=' Decrypted: 'Hello world!'
Output for 5.6.16
Encrypted: '1MSlfa5ZSszmBtcMoByo+T/CRFj3UU6byP9r9JRJxxc=' Decrypted: 'Hello world!'
Output for 5.6.15
Encrypted: 'XwILIB0HvjAhXCBeLohXmwC1nKvmUACEQaqWcBnnfmU=' Decrypted: 'Hello world!'
Output for 5.6.14
Encrypted: 'zbrjs/13DowzV5vb7U882Ov+YKfvA0giDHMbbRmIz94=' Decrypted: 'Hello world!'
Output for 5.6.13
Encrypted: 'nXQVGd9GmRBRn/msbRs/2B/HUdZzBK4TwkNzPyaizh0=' Decrypted: 'Hello world!'
Output for 5.6.12
Encrypted: 'iY0aQxvA5K02T8Z41LzUxU4QFbnioSUYX0MYx3mhokk=' Decrypted: 'Hello world!'
Output for 5.6.11
Encrypted: 'zNQ0f/B7adZzyr946PAtNwC860tEsjm0dDbFdUVcjPM=' Decrypted: 'Hello world!'
Output for 5.6.10
Encrypted: 'Yqm+Bb+CMp5qV6EEZY+2H0YZizEQlAMY4smiZJNzMlE=' Decrypted: 'Hello world!'
Output for 5.6.9
Encrypted: 'Oxj7FbBV6ojGmRKCOfHBi09vFg2bCy9YC0/WO3zLR6o=' Decrypted: 'Hello world!'
Output for 5.6.8
Encrypted: '+ISJErO7wHeFJq1+jonhcdXNpNlv+5LLT4Qx8vDajW8=' Decrypted: 'Hello world!'
Output for 5.6.7
Encrypted: 'cHuDWHPh74IfVB4OpFVQ/oJHjsYiC4SSAeFVU3p5YW4=' Decrypted: 'Hello world!'
Output for 5.5.34
Encrypted: 'TqNbFUUTQqMzFSwvr4fcVJQllqWLff+B/9PMZ5FPbmQ=' Decrypted: 'Hello world!'
Output for 5.5.33
Encrypted: 'dhMuV7/9WgctS0L0fzUJOsa315cPtJuVqSjK/vF45P8=' Decrypted: 'Hello world!'
Output for 5.5.32
Encrypted: '6KvoCvRtA6MIfS5SKfgjLSuurTku7Bl6+cAJ/qPFBQ8=' Decrypted: 'Hello world!'
Output for 5.5.31
Encrypted: '2uERUJpVn0TAb/AWLWsTg9bauAO4XKOPYTJQBQ4mFyk=' Decrypted: 'Hello world!'
Output for 5.5.30
Encrypted: 'EIWE3F5Ti0dV9egt2RX7NcbxUULkRUkMceCZt4S5JM4=' Decrypted: 'Hello world!'
Output for 5.5.29
Encrypted: 'C2KjV5uClVoE8OAoAMBFg8fxju7S6wlpahFVOld/n08=' Decrypted: 'Hello world!'
Output for 5.5.28
Encrypted: '9JpkVUGuhOuZnu8IVDZFvkiWagQ6PPZ6WFpRDfU6Bf8=' Decrypted: 'Hello world!'
Output for 5.5.27
Encrypted: 'JrtOaI9l6su1GBECxguAIMY6SXIbEOM1C4uNsOw2dgY=' Decrypted: 'Hello world!'
Output for 5.5.26
Encrypted: 'r+5nPkNm5dxbkHSI8HZ5auzerreY4Q4lEanPQ6bh69c=' Decrypted: 'Hello world!'
Output for 5.5.25
Encrypted: 'hSx1GYHHViV01Y4jOjJhfzFo9rwdj6ttEUSBbS04V1k=' Decrypted: 'Hello world!'
Output for 5.5.24
Encrypted: 'ZuhUbXIvvFoHO8nP5AJVis//ABhApf0EHQTkv6sJOJ4=' Decrypted: 'Hello world!'
Output for 5.4.45
Encrypted: 'dWS6OxEKqk4WDQDxeaskQ+SaWZcLamngDqo4uFiIDT0=' Decrypted: 'Hello world!'
Output for 5.4.44
Encrypted: 'fA9MdprWXo/xFXE5H5Bh6UCcgPytMmPvHBCoQayA0Zw=' Decrypted: 'Hello world!'
Output for 5.4.43
Encrypted: 'KwzQSq1p5IFfV8K44aS38eY09rTJbcg7jXVmt1i/0Fs=' Decrypted: 'Hello world!'
Output for 5.4.42
Encrypted: 'RZx2TC1bgLgteKwucJjfzTtK5F1tDVCYVBQ1YdvC42E=' Decrypted: 'Hello world!'
Output for 5.4.41
Encrypted: 'xVyDSuvDAPV3FTHMaZClNWkMQ1xY+svQnLQgJvZvwTg=' Decrypted: 'Hello world!'
Output for 5.4.40
Encrypted: '0ox+L3oHd/2bG3S7TUKAeT46HWvTSbMk+8Drtnw1Hvs=' Decrypted: 'Hello world!'
Output for 5.4.39
Encrypted: 'jpeoq9oKeMU82dnUyNLL3PxTSKvhqIUBECOsI7x2260=' Decrypted: 'Hello world!'
Output for 5.4.38
Encrypted: 'GS2rmKTtVUEVFQHScIcp+JqW9y8aHeGxBP/xPOuiPXU=' Decrypted: 'Hello world!'
Output for 5.4.37
Encrypted: '1gRvNEOxNMpCUwTHzICia3XFPggipdjOi0Sk+bPNfuQ=' Decrypted: 'Hello world!'
Output for 5.4.36
Encrypted: 'XVxff3mOpCX3fn3G6ZfaVB464GivjkjhubB3X+z8uo0=' Decrypted: 'Hello world!'
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: mcrypt_get_block_size() in /in/XKTd2 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: mcrypt_get_block_size() in /in/XKTd2 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: mcrypt_get_block_size() in /in/XKTd2 on line 3