3v4l.org

run code in 300+ PHP versions simultaneously
<?php $key = 'password to (en/de)crypt'; $string = 'hello this is demo '; // note the spaces $iv = mcrypt_create_iv( mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM ); $encrypted = base64_encode( $iv . mcrypt_encrypt( MCRYPT_RIJNDAEL_128, hash('sha256', $key, true), $string, MCRYPT_MODE_CBC, $iv ) ); $data = base64_decode($encrypted); $iv = substr($data, 0, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)); $decrypted = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_128, hash('sha256', $key, true), substr($data, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)), MCRYPT_MODE_CBC, $iv ), "\0" ); echo 'Encrypted:' . "\n"; var_dump($encrypted); echo "\n"; echo 'Decrypted:' . "\n"; var_dump($decrypted);
Output for 7.0.6 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Call to undefined function mcrypt_create_iv() in /in/bMkW0:8 Stack trace: #0 {main} thrown in /in/bMkW0 on line 8
Process exited with code 255.
Output for 7.0.5
Encrypted: string(64) "rZpnogkZWm7hGLNjTaUXU4hqLLAfO3bi50ZcvKCzgp5CgYFxmHuaQkN5OrqtqBWs" Decrypted: string(19) "hello this is demo "
Output for 7.0.4
Encrypted: string(64) "BeEybAfy0ar/amj297LCCTEWHoh6+qbgeKZY2GCcG1DnfjkYQBuI6mttjJW5MtL+" Decrypted: string(19) "hello this is demo "
Output for 7.0.3
Encrypted: string(64) "Fzb2OwuZPc4uhiYdCTNdxx4o+T6llNjQAO+IaXbIZIjsUjEofMSkR4Jchdy7751c" Decrypted: string(19) "hello this is demo "
Output for 7.0.2
Encrypted: string(64) "SmPuDXmhjr2No8D+NGGB2IR/R0rXqk2nCj8D88RMU1rotu8vssIMTnJEg2EuTClG" Decrypted: string(19) "hello this is demo "
Output for 7.0.1
Encrypted: string(64) "HjktAT9wfjM1gTSbv+RDVoac51mgMEBXCIAhPYkN1ofzWFgwqIZrOd6aM668Qmc8" Decrypted: string(19) "hello this is demo "
Output for 7.0.0
Encrypted: string(64) "VHIM+8cdTMsbsFvM8Ryoc+fdzLMisO8fuEUPohqVCpPwxX48tZ5RQ8aKL7lx46Mp" Decrypted: string(19) "hello this is demo "
Output for 5.5.35, 5.6.21 - 5.6.28
Fatal error: Call to undefined function mcrypt_create_iv() in /in/bMkW0 on line 8
Process exited with code 255.
Output for 5.6.20
Encrypted: string(64) "zTfEmkf1B8tZXMDQpWPwjHklJrky1eqIjLR0gxEg0GWIFpYL2bK2EAg5tcSMiUpR" Decrypted: string(19) "hello this is demo "
Output for 5.6.19
Encrypted: string(64) "k/2tcllburaT73hPRlfo6Tk75oXcAeh6ROfsDjVYDwp8tUUphovgFHaTPXcxK2R/" Decrypted: string(19) "hello this is demo "
Output for 5.6.18
Encrypted: string(64) "Af5qQV4drPUYc8kl62WQaGVmqcD+kGnwOCIxZP5F2fOeJjZ7gkcaE/3+RahEVJPA" Decrypted: string(19) "hello this is demo "
Output for 5.6.17
Encrypted: string(64) "O4GczyrCNoG3IdEmAtDIeGoCDk6ZCwwoR4w2NdtJEIcyZf2yGg6rww9xPNAWdiDD" Decrypted: string(19) "hello this is demo "
Output for 5.6.16
Encrypted: string(64) "rjYwIVDlj3sVTwCvLwNsoQxtss0Fu9qT9oDjcufBO14b6QLt2vn0CTYSw0IONVmA" Decrypted: string(19) "hello this is demo "
Output for 5.6.15
Encrypted: string(64) "peEbqX/Np3GQhYe4fpaqBYm4lj1OedmaIahyYEQCG5maMrX2nW854FYFeFMNIZAL" Decrypted: string(19) "hello this is demo "
Output for 5.6.14
Encrypted: string(64) "CpCCrv46uhBkhkICRqbEyPlaNLms8azDJ+prNIEBhlfRietakvEtWIsDiKhDAzpj" Decrypted: string(19) "hello this is demo "
Output for 5.6.13
Encrypted: string(64) "Q9T2eOTP5mEbeOgArAOX/xeuOrmtOnnno1hc4WK7RWsdY3jLcAva7UBEuFDxKoOw" Decrypted: string(19) "hello this is demo "
Output for 5.6.12
Encrypted: string(64) "4gl7YLpwXxJM44yTk84A7G2SKkoLgcsVb4+IkOYAvWdRBFyQECaR1jZZ8rJHmk52" Decrypted: string(19) "hello this is demo "
Output for 5.6.11
Encrypted: string(64) "KgCm8Gvmur9MFl789xoV9AzSwJJ7+3u6cNBV7BMzxe29sPbQNbrPaCDdU87UPBqS" Decrypted: string(19) "hello this is demo "
Output for 5.6.10
Encrypted: string(64) "vbOHCPyw8+jAKqAdO84gTMHtsxGVE0H0A8z7rFlRk9bMIYilbqPdnevb/Y6g37ru" Decrypted: string(19) "hello this is demo "
Output for 5.6.9
Encrypted: string(64) "5Qq+TzavtFpaZ7uDcaOD1+nCwQ8qOKUHzgsTGunEMc/Fu2I0gGtfHvAagvDs2E5t" Decrypted: string(19) "hello this is demo "
Output for 5.6.8
Encrypted: string(64) "LrTUgnWlLuwtoEye5x3VEI6RqNyi+iRRXmcGLwKpsbMGT6f5ry2w2EOK5GUDyYxz" Decrypted: string(19) "hello this is demo "
Output for 5.5.34
Encrypted: string(64) "tm1yq8RbZDv28u1MpbfAtBXcIO6BIG3cyjJBAefsJbi1rbU8anlhtK6qtKu0O438" Decrypted: string(19) "hello this is demo "
Output for 5.5.33
Encrypted: string(64) "o6q3mSsc0rTxxlJ79tZZEEw+BAqBPm4FOaYQM25/NbUpybBMcd5UjU0ATnOB8CWS" Decrypted: string(19) "hello this is demo "
Output for 5.5.32
Encrypted: string(64) "bOisCjLov37qR3/+D7dx+P2F5aFrnYZacoK/sNKDAtLIo4+CwKohuvwkXsKZXUgw" Decrypted: string(19) "hello this is demo "
Output for 5.5.31
Encrypted: string(64) "iHWxbgP0Par6k4V8wRtiTkS9W8HqRekMx+tKh9qLjb2vgCdGUgfOPwwpH5fwZhrn" Decrypted: string(19) "hello this is demo "
Output for 5.5.30
Encrypted: string(64) "S0dPTmXD8GusWK4oF0uzc4fgALRUExeAzkrYCs0jSovCLeHVPexczCavMses7pMY" Decrypted: string(19) "hello this is demo "
Output for 5.5.29
Encrypted: string(64) "s2R0N2eE///lcN8zMsKmsJ7VzDavis9cCSIYY4S6kC7JxzF7itGd5Yyb0dEXhBq8" Decrypted: string(19) "hello this is demo "
Output for 5.5.28
Encrypted: string(64) "0ENANcBQSj3cWu9qFzPIKnaCSHgA+VyYxin3pBkdpg12OO1dLpOGNVwe/c0pod8Q" Decrypted: string(19) "hello this is demo "
Output for 5.5.27
Encrypted: string(64) "4q0xzyK9XxN1HJUZR2heIOICejOtBLgtfEHWWtAXAZXFXh/QZqc9n/IzZc0ezZ+8" Decrypted: string(19) "hello this is demo "
Output for 5.5.26
Encrypted: string(64) "Onr0xM4mHuIEQPUCRP6CJkTIfoW2LhoJzhHXY4VMvgmllz9UBOjEYj53yjNJiK9q" Decrypted: string(19) "hello this is demo "
Output for 5.5.25
Encrypted: string(64) "ssS8wlm3TpndWOY1Lm08GtKk4422onY14cFE/zylzySpswTCY5uoxoua6KI5tcPh" Decrypted: string(19) "hello this is demo "
Output for 5.5.24
Encrypted: string(64) "F3HJ5H9RVM+nTwqf21aL2VV5cwh750XYRQObVeqB0gicFcsfiHMmBDFSZUGUV+xX" Decrypted: string(19) "hello this is demo "

preferences:
173.63 ms | 401 KiB | 183 Q