3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php error_reporting(1); ini_set('display_errors', 1); class Encryption { private $key; protected $iv_size; protected $iv; public function __construct() { # --- ENCRYPTION --- # the key should be random binary, use scrypt, bcrypt or PBKDF2 to # convert a string into a key # key is specified using hexadecimal $this->key = pack("H*", "myKeyIsGreaterth2nanndbestofall04nkdsdffsd546754sdfvsdg6efflsdfs"); # create a random IV to use with CBC encoding $this->iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND); } public function encryptData($input) { $output = $this->encrypt($input); return $output; } public function decryptData($input) { $input = base64_decode($input); $output = $this->decrypt($input); return $output; } protected function decrypt($string) { # retrieves the IV, iv_size should be created using mcrypt_get_iv_size() $iv_dec = substr($string, 0, $this->iv_size); # retrieves the cipher text (everything except the $iv_size in the front) $string = substr($string, $this->iv_size); # may remove 00h valued characters from end of plain text $output = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->key, $string, MCRYPT_MODE_CBC, $iv_dec); return $output; } protected function encrypt($string) { # creates a cipher text compatible with AES (Rijndael block size = 128) # to keep the text confidential # only suitable for encoded input that never ends with value 00h # (because of default zero padding) $output = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->key, $string, MCRYPT_MODE_CBC, $this->iv); # prepend the IV for it to be available for decryption $output = $this->iv . $output; # encode the resulting cipher text so it can be represented by a string $output = base64_encode($output); # === WARNING === # Resulting cipher text has no integrity or authenticity added # and is not protected against padding oracle attacks. return $output; } } $test = new Encryption(); $encrypted = $test->encryptData("Narendra"); echo "This is encrypted text of a string Narendra $encrypted \n"; echo "This is decrypted text ".$test->decryptData($encrypted);
based on MnJGQ
Output for 7.0.6 - 7.2.0
Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/3DdoQ:19 Stack trace: #0 /in/3DdoQ(70): Encryption->__construct() #1 {main} thrown in /in/3DdoQ on line 19
Process exited with code 255.
Output for 7.0.5
This is encrypted text of a string Narendra XGHPBa++i0xP2tawGUu0oT1BPCbThxT+BMi71c1tolbMQSM3qeppI0FghFfGqi8Iuzbu/z4CPswp+w+p0AJpmQ== This is decrypted text Narendra
Output for 7.0.4
This is encrypted text of a string Narendra 4fIZCLyYfR3oBaxJ25CK5uITSkqBJ8tmlgYDK2/yvthKJHU7z6q/N4PYI87qa6IgpnQzk+zfrLgJU/GNuK62mA== This is decrypted text Narendra
Output for 7.0.3
This is encrypted text of a string Narendra URAD6yytiTlGyRBl5Xve8JaDmrXJitGqbm++mLxPzmQNhSJaehtbYINz89jdT+GcQr9mCdS54o/DP73hpOtKbA== This is decrypted text Narendra
Output for 7.0.2
This is encrypted text of a string Narendra 0h45wgIOQe6nbEOsqV0inASItOutjMSQGn47Qv36/A+Q+EfUEM6jiEd3sMDpSoVZvyq31QUwgRJhGhaWl14PpQ== This is decrypted text Narendra
Output for 7.0.1
This is encrypted text of a string Narendra QFFwC3a6iMA6LCCBQnNEPI+T2dxD7toeTzOwjzrFDzRr6eJ0JIB8StcaiEdlinxaz8B74YRqTEGoAmYKkkZv9g== This is decrypted text Narendra
Output for 7.0.0
This is encrypted text of a string Narendra Ysxbw8972ATMO6ZwuKasno5FHDxKqx/tFqxf80gRgJ6IvLp2GZZdB2yKFuXqMj+vvLMif6715OFDqBTjkefcwA== This is decrypted text Narendra
Output for 5.3.20 - 5.3.29, 5.5.35, 5.6.21 - 5.6.28
Fatal error: Call to undefined function mcrypt_get_iv_size() in /in/3DdoQ on line 19
Process exited with code 255.
Output for 5.6.20
This is encrypted text of a string Narendra NNHV6TKGLAItZR9r+qwvvZ8LQyjwxiyj+Yq+iCvCkEkcmivJqmDEoOfhBFo8K1w+cvoI563Hxlj7iUA3wzT0EA== This is decrypted text Narendra
Output for 5.6.19
This is encrypted text of a string Narendra 4iL0Rny76q13mYa6pGj1zZYYtUCMVHm30PMRSyPlvJwYFIAphZp9iAKci8bL22tIA1xmJohq5MxcNXbkqbF3sg== This is decrypted text Narendra
Output for 5.6.18
This is encrypted text of a string Narendra MTN00s1C5pKustAXiBt12WWbN6DLd75zcLLE6e/vnl0jHAkBbbz3yPYzG0uOqW7xqVJfYe8hQGev91NAdJqtEA== This is decrypted text Narendra
Output for 5.6.17
This is encrypted text of a string Narendra J6zxYWP8kKtZ8KQ9aqPbkj66A+Nu475C24xSc7rQjsTqWa7+MucmatVdMIvwgCdvXtG7+ujdePOFpd+eKC3Huw== This is decrypted text Narendra
Output for 5.6.16
This is encrypted text of a string Narendra xGPXCjRjy+XcXUgygqwpFF/EOJepA1kNIb7AjkVNFLn3NEErsqGRKNw+yxFmETF3Yc98xM7ltdHfCPmReAi6ag== This is decrypted text Narendra
Output for 5.6.15
This is encrypted text of a string Narendra m1nsOXPm4XdVhQVrCK3mejYjYUbDQfruaThP6RbT+GHCJUBqkXnyU/ZC9w/m56bhr0xQNl0pqfvtBpsIPLWiRg== This is decrypted text Narendra
Output for 5.6.14
This is encrypted text of a string Narendra jlqgiKysr+cbmQ0j2wwd0a+DgPYlxcwgvLrVisZ5FQVrGQlPkT2LOJzv08qV6itId5WTnKtjAfGg4Nj8Hp9/9g== This is decrypted text Narendra
Output for 5.6.13
This is encrypted text of a string Narendra o+WY+zCBG1tdSHsQW0tSicCj5j7rqWlYf7bqamhzZ6e80gPu0VZZvOXKLd20RS0TSRvw+gZWvmSNa2TLOklhAg== This is decrypted text Narendra
Output for 5.6.12
This is encrypted text of a string Narendra CBJhNvOPUCJeyn0T8kCh4A7x/qkzanQYeB2iQcPzPdDFiyi6K5Ec7Oa2nDvBYva5STeFwTURRdoEnnQgt2U1Sw== This is decrypted text Narendra
Output for 5.6.11
This is encrypted text of a string Narendra Vr4d8wDgyMOW1po+JIHRAey7ixSQKKob+hJ/FeBJnGG52SdR6TtJGcvcpxsjahz//5Xrv/kv+Xrvwf9HUofKxg== This is decrypted text Narendra
Output for 5.6.10
This is encrypted text of a string Narendra Gezu2GXvf8mxFjx4Mcj2OJuSjPf1+Nf0xnOH0/k0TT8ldcc9sibmvw1nVxz2jVWsw493xeqv6uGcs2rgD+8VOA== This is decrypted text Narendra
Output for 5.6.9
This is encrypted text of a string Narendra AQUZNi9Yx8lTmvmfLruQH0Re+pLZUJ9LRajaCqJsgclDVzi+iK2sC0Nt9z3XONc8tzzlRd7Ba7KBEs0PDramLg== This is decrypted text Narendra
Output for 5.6.8
This is encrypted text of a string Narendra +5AhDTzg6pyvbldb5L10bBBxDzPaAQdQwCd8g6TEJu2UZKsY+2lKmwQpTYHmhY7AUumOaaTGZslO7A3mHR7yJQ== This is decrypted text Narendra
Output for 5.5.34
This is encrypted text of a string Narendra XR+JSypG3AhXPFoA/llTml9reU/x0NPdIdzhH2QKeRGLx36R7Sbk265hFdBdY7WoOxKi+0g9If53nSGAnSLWcw== This is decrypted text Narendra
Output for 5.5.33
This is encrypted text of a string Narendra ZO0jpyjPYLTAmhctGYeKztQafQqIsn8QalFWAht+Abu0sd6m4TfxEuAwLAmvQFalR7L9HXLZMvvYGNpr2PzS+w== This is decrypted text Narendra
Output for 5.5.32
This is encrypted text of a string Narendra 84gX7Tn1SvQjCLiGU0MeryGUo+3MOH+GQ4rtumEJOAVWiQMnH31U4JSwY4bQpmYJtQCdAbL4WEbv4wMmBJwEZw== This is decrypted text Narendra
Output for 5.5.31
This is encrypted text of a string Narendra Vr2Oj+M/UqHn7s8R0POU0Kkan6YvWiR2faK4qC2v78YE6KyC6eo18fHGbmBGZqz82HMw1ERAwjvxiV0c2OoYeA== This is decrypted text Narendra
Output for 5.5.30
This is encrypted text of a string Narendra s84sSSYduo1Z2ss8xt612Uz8AzkHYbhtEbEMJl2ojWqPI8TWWT0XzV4TQ+NZFxDhMh216gVRzWSGxaeSZSaSKA== This is decrypted text Narendra
Output for 5.5.29
This is encrypted text of a string Narendra YNxJy7PHCAi6vZKBbiA6tX38M31Jfe5CZoHnIIdkYpP8kCdKyulITmjd2pA0mXXr/6DqFon7rRO0goEUlg+Qjg== This is decrypted text Narendra
Output for 5.5.28
This is encrypted text of a string Narendra xKTq+IFfJeu7PJu7Wg0Nw/RAmcT0HR1Dsz2oVXJgfcv/KFECIgbFVJQU0LETysIX5KbTQufYW2/jX+XPDcH4MA== This is decrypted text Narendra
Output for 5.5.27
This is encrypted text of a string Narendra Z/V7GzOfil/Qxgs0GB1VDiimsVMQJiJlyzs79cfbzkuixlEhbXlv2Tf7CRNwkp+FAu2xdWCQ6UtcYK1XiR6CAA== This is decrypted text Narendra
Output for 5.5.26
This is encrypted text of a string Narendra YVwNRs+KHj27DnGkAO1CRTtGp/wqGG4LqpeEzm0unBonrESyluOeeqv8v3QFQs++dPmE4GGpEnMSNywkUAGXWA== This is decrypted text Narendra
Output for 5.5.25
This is encrypted text of a string Narendra TcGGeH3dNkMPWYFev5NXXu78Cd+Wuqk+25oq4ZdYZdN3iBVYGsrG2uWF2xWbYCUW/E+Gjv9kOVPd5OxIe0hNBg== This is decrypted text Narendra
Output for 5.5.24
This is encrypted text of a string Narendra gZRBNI30ix28B7gI74N4Gv1umHaiOhbuO4gzMm3uuU3uJTtSQ9ULklkgoq02H2rIGLsvmikHzinnVGFhgrtbaA== This is decrypted text Narendra
Output for 5.4.45
This is encrypted text of a string Narendra ooMJ9/s82BrCykIN2pUVgfmjbg7H2c5iRyxuYKivL6p5owWUX46/WymQ9G/iDxadyEQjOck3Ogwjgs6un5lPVQ== This is decrypted text Narendra
Output for 5.4.44
This is encrypted text of a string Narendra X8CXSqoyhFx3aA4uMnlDhubJ4XK1FS2DQ59NJyyaHRQghr2UYxeBZrDUoyoJk+F+1yxWz/QAB7IyO0b569nplg== This is decrypted text Narendra
Output for 5.4.43
This is encrypted text of a string Narendra /liMdoSNaiWsvEcUtaUC0lbJNUsyar+8Ubjg2zzHjYfC2FMcgWnEv8RjvlV6YBZo94Ui8+dSGWEX/vVmH/Oang== This is decrypted text Narendra
Output for 5.4.42
This is encrypted text of a string Narendra NGetgtp0h+XXUNIlm/sIj74omv5im1YnmLjkqg8wYLBeCTQ/cLjtZBAhu03WerwSSyiUkvnejh+Qzkh8IGD3dg== This is decrypted text Narendra
Output for 5.4.41
This is encrypted text of a string Narendra fR78C5gEpsSaNyOjHPa53/zDwzZ5A3EKQCLMXg9ZonGOFiHoGEgyftzqgiOAteX4t/cGJgSemliyyu8mOEkX1w== This is decrypted text Narendra
Output for 5.4.40
This is encrypted text of a string Narendra YbUipatmkEuNkRWTZimQeexwDwdw9XnrIxzwlcNHoLvrrL/Wu9O4lI1bGOui+FjcB/vJMPzOd/1oFzHMhKWrWg== This is decrypted text Narendra
Output for 5.4.39
This is encrypted text of a string Narendra jRteHljoe/hOLeMqAacIdGCuOkpEpzqkNrL7w7kLlm7H6R6cJrsRU8w7o05lyneKDrIMO64ozW1Qj/IC09zdfA== This is decrypted text Narendra
Output for 5.4.38
This is encrypted text of a string Narendra D1uHMc7bJqTe0FAqAsjNsaXq838CZ4fWH+JgX8wjpN2hSyFVhUn/WOe8QhpyX1DLRXvfEGubF2/PRuj5Jmq0kA== This is decrypted text Narendra
Output for 5.4.37
This is encrypted text of a string Narendra zCzqFagHi5UIWufe9AFXdvw92zHqUVoFm+NIzfr9mrYHX0ojA7+mKHPeS88lGfxF8BWuMvHsbpjjJn44Wi7nFQ== This is decrypted text Narendra
Output for 5.4.36
This is encrypted text of a string Narendra Jz10/tQTDzAmCs4fG5wmdlu2AHR1B/om5Mzt6pZw1CcaEj6e27Q4ZV4C+WES9Q91W3LW7/ffuns18SME3lFWxg== This is decrypted text Narendra
Output for 5.4.35
This is encrypted text of a string Narendra JpZcWeMt2564aBX3EH1V9hQpz3rsQVFD3O/nYPFBYMy56oqsYYmQUOgZDVKYFTPpmZgT4LrpUiVXOj/tUZBmjg== This is decrypted text Narendra
Output for 5.4.34
This is encrypted text of a string Narendra AJOYjL+RGhCXfdvvcNbNsNK0ZDfdS3x0oW99GLqPsHN4A91CJfXN669sxr1E+Vm8SDcQkWBOkKX+Ab3uke6Q8w== This is decrypted text Narendra
Output for 5.4.32
This is encrypted text of a string Narendra O8IouwGr6HnM8qT5c1v+Rb5ZimRtptyc2sQzas5GyH+XywjqCIbzXvcAF2hPVqQ1P16VhO5k5SQas+I4wFDkwg== This is decrypted text Narendra
Output for 5.4.31
This is encrypted text of a string Narendra hL+dLZPjLi4zUccBjsx7emf1ajLfQn8gWB/6EOsXuFdwgZ8yIXDcLOTYZLN7JL9BMifikfeVaPHyxxfhydoo0g== This is decrypted text Narendra
Output for 5.4.30
This is encrypted text of a string Narendra S++Q+Cl8Sq37TAcAmTZupXR39iFmU6DLIIxVykHjdFE3OlXvdRFTFy/JcX8LaANVDmKlV2YO2nGnUbLgi4PlLQ== This is decrypted text Narendra
Output for 5.4.29
This is encrypted text of a string Narendra QC/SKkQHyMQJnym5nuiFdvSyrutIctktoZxk3W80NhYMnzlgDbahSugwu91SZykRFuU2oj/b1ZOU7JIwZCSwsg== This is decrypted text Narendra
Output for 5.4.28
This is encrypted text of a string Narendra ZfIzOa3fJ5mElW8pDxN/MPaY0pUj9kgA5LmQTnebcyw7YQKjFdGPji9JvupNau5N7ttv2ajmcxEpmElzL14VNg== This is decrypted text Narendra
Output for 5.4.27
This is encrypted text of a string Narendra YZS7vs4o1LUwTqZWYpQEP6zrZPJf2YbJyNUF8nXnlKI8+NGVy53BglqiBl4On/sL4AO9pGnijbXn37iGsspAKw== This is decrypted text Narendra
Output for 5.4.26
This is encrypted text of a string Narendra pnFDYjSO2boyPPI90So/LEg3/LnRfGYdKOifNlEiokTjR+bWZp849JjQzMX8tpE4Tvn7Xz7Fw+zEXtSgLyas1g== This is decrypted text Narendra
Output for 5.4.25
This is encrypted text of a string Narendra ZPqP5X56CRzHMEBusICIaI/ZDs8Pe/Afc9BYgFLomH68rZ2YwerP3BWBVZyM1RgUErypQKpQ6prm1IO2N0zh5g== This is decrypted text Narendra
Output for 5.4.24
This is encrypted text of a string Narendra NSuFWCa0mVMGYUPmBGY9gfHgK/pSJRC0cfbqRa5BFNuagzXCN9MkCUSk8P4h+E6p2HrUIMTC1c/pdhhZ2RWWug== This is decrypted text Narendra
Output for 5.4.23
This is encrypted text of a string Narendra s9jbLXCjzEKucfft+NF2xej6IAX9nDYSlniv3YBDr4Y6gQYSgCHcD+E3nAQmHR0aZm0dD/ja/WkpYV2y6XGxTg== This is decrypted text Narendra
Output for 5.4.22
This is encrypted text of a string Narendra CzbZcMaNXtvIi/s2ZWQrd8PIFFtDSnUajxk7M+svDZlqkqA9jYZgv4F8ERcI+hzAVvzYbf2Vkh/e8WiUTyfWNg== This is decrypted text Narendra
Output for 5.4.21
This is encrypted text of a string Narendra 8McyPg96ahk7gCviEDCZes+UOcR8RxfEV2aiuFIT/LF7qxIMjUv5GePgINJ/3Y1t0ZtzM9glqP0to2mMR8L4vQ== This is decrypted text Narendra
Output for 5.4.20
This is encrypted text of a string Narendra JpVm0UVEIT8lMryKmti/+JtzA5RI91Pk+me/T+5pHlSxDI5+1zZCTd4XjpfGRUw7XQ8Qu5GmIraVSy83gmgcWw== This is decrypted text Narendra
Output for 5.4.19
This is encrypted text of a string Narendra RYIlfhAL/Rbheu1rTEtKcdkEyKCfHdUKT2JLU/zpJMZ0y048BkTmG3EhTJ/RT2M5y+OpOqU8OyWlE7mmDNV75Q== This is decrypted text Narendra
Output for 5.4.18
This is encrypted text of a string Narendra qdReHnYLm4vgd6hn6oUBXxBX8c/tbD5NQFlr4zgX2IsuZqHNRAyOxm5A3cF0gl2itUxDNK9djm9ECMe+To5Blg== This is decrypted text Narendra
Output for 5.4.17
This is encrypted text of a string Narendra z+rXucVVwUIwkNd5yGWQC9yZueShQd0Sex+ff+pB8hZT59n9VkmosNso0PsTl/uwkqfsAGCJfenFh66ZFq7ivQ== This is decrypted text Narendra
Output for 5.4.16
This is encrypted text of a string Narendra 38UR3A7UDgkoqMyW5Ux5Bb/dPReGov6QKIMvh7kacAKDjmrOL/GgBO9+fLS5f10r1KCYQ93JdVrG9F36y973QQ== This is decrypted text Narendra
Output for 5.4.15
This is encrypted text of a string Narendra Oc8ERit362Tyr73snA1UxgKSJiYrD2PHd4bV4llpFvKM8lmW4gHeFVSwvR8KRzu+2541/fi6AXmGLQG9xQgraA== This is decrypted text Narendra
Output for 5.4.14
This is encrypted text of a string Narendra Z8B+dkKPRkJMPn/Z8OAWoz0qZQugL9VUaFC90glkBfAjG0LG7i6UbNaaIzLzWKFOjytU/wzYB6dnLdoJS5TVBQ== This is decrypted text Narendra
Output for 5.4.13
This is encrypted text of a string Narendra 74S2LhUZP7dAqFsHpzZvgKjtkjqgp6d0WvnW0HhGyMHS0RssLeSYbI+8aIMdI4xF6SfkgJQMHmmQ79hUF4iguQ== This is decrypted text Narendra
Output for 5.4.12
This is encrypted text of a string Narendra bAVXRw6l9pH+0XKbtHB0bY4617RtKahlUZhUVLiAKCWGHXToqRJ2KK/Up2+JH0hz8T/u0gjknHURKYaBGx0v4Q== This is decrypted text Narendra
Output for 5.4.11
This is encrypted text of a string Narendra 8EFPImBAbn8u3UxLGBvRmY7vY67XLTEWzTNHgJjFGc0uh2zsL46Dyc7UIVsrIYMDm7ZMotxmPp5LL7Khw/ffTg== This is decrypted text Narendra
Output for 5.4.10
This is encrypted text of a string Narendra dPbCZ3iwJXAtOhOGGmfJoUxAmfHOa4OiY3iHt0PFEgx3+SyM6CE1pdIyxyTWKuJrnnb/hEVqVnjX5ki+Lfu7SA== This is decrypted text Narendra