3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** * http://stackoverflow.com/questions/9262109/php-simplest-two-way-encryption/30189841#30189841 * * This is not safe to use */ class UnsafeCrypto { const METHOD = 'aes-256-ctr'; /** * Encrypts (but does not authenticate) a message * * @param string $message - plaintext message * @param string $key - encryption key (raw binary expected) * @param boolean $encode - set to TRUE to return a base64-encoded * @return string (raw binary) */ public static function encrypt($message, $key, $encode = false) { $nonceSize = openssl_cipher_iv_length(self::METHOD); $nonce = openssl_random_pseudo_bytes($nonceSize); $ciphertext = openssl_encrypt( $message, self::METHOD, $key, OPENSSL_RAW_DATA, $nonce ); // Now let's pack the IV and the ciphertext together // Naively, we can just concatenate if ($encode) { return base64_encode($nonce.$ciphertext); } return $nonce.$ciphertext; } /** * Decrypts (but does not verify) a message * * @param string $message - ciphertext message * @param string $key - encryption key (raw binary expected) * @param boolean $encoded - are we expecting an encoded string? * @return string */ public static function decrypt($message, $key, $encoded = false) { if ($encoded) { $message = base64_decode($message, true); if ($message === false) { throw new Exception('Encryption failure'); } } $nonceSize = openssl_cipher_iv_length(self::METHOD); $nonce = mb_substr($message, 0, $nonceSize, '8bit'); $ciphertext = mb_substr($message, $nonceSize, null, '8bit'); $plaintext = openssl_decrypt( $ciphertext, self::METHOD, $key, OPENSSL_RAW_DATA, $nonce ); return $plaintext; } } $id = md5(uniqid()); var_dump($id); $key = hex2bin($id); var_dump($hex); $message = 'Ready your ammunition; we attack at dawn.'; $encrypted = UnsafeCrypto::encrypt($message, $key); $decrypted = UnsafeCrypto::decrypt($encrypted, $key); var_dump($encrypted, $decrypted);
based on jl7qR
Output for 7.2.6
string(32) "98f6811d42459ef347e624794ff31811" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL Fatal error: Uncaught Error: Call to undefined function openssl_cipher_iv_length() in /in/vsqNe:21 Stack trace: #0 /in/vsqNe(81): UnsafeCrypto::encrypt('Ready your ammu...', '\x98\xF6\x81\x1DBE\x9E\xF3G\xE6$yO\xF3\x18...') #1 {main} thrown in /in/vsqNe on line 21
Process exited with code 255.
Output for 7.2.0
string(32) "e65a0e3721f76db5adb04f24e264f8b7" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�.X��t����fpβ�y' �� ��i���f*%����M�xm�0N������$" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.10
string(32) "181e61ae991ffa84909408ddba0e318a" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�kվ�����Ob������o됖Ͼ#d1v#2W  )�[���_y����ԡ4ۣ�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.7
string(32) "d527b7fd0fa2cd2c8770e3bb1e9b8216" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) ";���+�B�O�^P�vk��SO����b���@�=��#s���A��x�(�����Y" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.6
string(32) "8a4fdcdc6a6e419602dc981397f81330" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "��� tӵdm��.铤�@Æ�� �<֭H"GObٵ�\�^�LlV@M�m_����!Z" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.5
string(32) "3710d8b58c36ff3135051bd68bc4b7d7" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) " �cX�D�@v���]�l=�;����� 0�%�j� ������N-X�j�?b" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.4
string(32) "059986a867b2010c394985cdf51bd892" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) " j�nV�g_=�ꕮ8vi*��g'��ff%$� �b/q�H<�2�,�} " string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.3
string(32) "8548e1a44ed7b4ab83e98bc5f812235a" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "{uD���v�ʊ�+X��m1�^O Eܖ����1��+8�z�g���E�tV" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.2
string(32) "11bbf956c0a3cddad802f672a170e79c" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�,�y���;ؚi�LCz��@��6s,�߮�괬%�=stO�{?�e?�S�&�t(�:" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.1
string(32) "28be9f673764063d82bc94cdd543bb30" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "ީ�H�x3H5����������Y~�A1��/�JD;�,�J�1�S�x �:�/A��" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.1.0
string(32) "6d66aac730dca8d01241b220ff83a821" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "ΕV�2�H0NҖ��f��b�]J%������Σ��� d� ��������ྂ ���o�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.20
string(32) "7ae072afeae2a7fcf41232a5b85fc102" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�!��t�-uRPc���`ڱ��!'�TS���$�覠<?����w�4�7D��9�r�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.19
string(32) "dbd7d60705870ce4883ce4019bc5b90b" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�f��F1|��_��RF ,O\��Xe��+7�SQs����6��m�8A}�<(��As;" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.18
string(32) "338a0136b2be8ac50086ea33b5639ee7" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "z� �w̆#�T7t�R���<,0W�0�|�m~��N.���ٽa;`s��B�Ѯ�'���" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.17
string(32) "974b04b792d6749550deb228491214e5" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�Ͷ�%�������St�`��y{}����(f�a����<G�R���8f�kW � �*�D��" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.16
string(32) "84543aaa71919373f25e344b7367eda7" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "~A%���P� b ;.ө�i.�@3�P�#�זH�yL���6\��N5�l�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.15
string(32) "8252e79378fd71b9a37aa7397e213a20" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�ܰ�_�S W��6�,���� h���>z���4'@��'�t��2t��y&s��" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.14
string(32) "28dd821e0185c89ea4c5499da872dd3a" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) " ��k���k��8sG���''�>2Y��T|�m�A�./��VO�X_�ɈY�Ա�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.13
string(32) "a98fd47a6bda600d2fff7da4e4b14153" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�!����CB��%�蒹���ϩq;�*:��k}���$8[� TA�f�3���/���+�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.12
string(32) "6feffea38b447784725c5b1e59160a1a" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "Ʒ1��� S_3��g0/�'6���{�_!�3���� |�}򀀁��**��t�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.11
string(32) "5d931caf556213a70cc86fcfdec4f5c6" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "nbSD�h8�"Ts����"c� Q�Ri��GmH�b�=U߹Cv{!L��p���'���kI�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.10
string(32) "6edf1a7af72da800e702c8324560df2a" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) ",|[[��[3�=&��Th�d�d�O�� ��i��� ϧ��ݾA�H�{��a��" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.9
string(32) "59fb1f40b19c35e346d516da2e383164" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�tm|/"��^�9b"fS���r<CN���,v����>o�|v\2�A�M�)����A" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.8
string(32) "2fd77e532b81357bef130199bb49b88c" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�me�vf��vW_�=3Ͻ���H23f���Sa����.���/ @��d�~��gF'" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.7
string(32) "06ffc04994ba428df8ce1a55e3dc9e8d" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "� QG�M����>�׍0��m9�r�K!��r5gS X]Ʉ�j�.j��X�� " string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.6
string(32) "f0d6e117f2d402566db193c397353b17" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�ڕ2_k�۩\��2S��� 9��E�tp�f�l��Dʫ� ���Y�͝>�P��ّ�mk" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.5
string(32) "f9856fecd2ff93793142b889bdd62646" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�� �auv^�o�Qr����ڄ@��m(���ٝ�h�K� <�m{ &� �S���" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.4
string(32) "b483415f3bc9caf306a5ff971a3d5465" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "q�c?�¥���8ߏ��S��'�A�Ž~�����[����k4�Gt��6�AV����W��" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.3
string(32) "d5ac0b4c949780661abe6f3104f07054" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "w����lE�x��ؑ�!<z��5@��� ���9�<[L�C. 3iN^b#�L�'ƥ<�" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.2
string(32) "323984fb7fca7b5134eccc9b0e93e64d" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "`[�N���;�u�W���</�Y/r!{��8�` �r ��� ~7�^�h�yՖ��&fV" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.1
string(32) "c5fe4de55999a72ff1626083b4f53722" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�]��`j5�d�2�I��H�;�d<����: G;�I�ԩ��� � {o�/'^Ŋ�*" string(41) "Ready your ammunition; we attack at dawn."
Output for 7.0.0
string(32) "e5488b32033ebde750b3d1626eff6162" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "ߛ�$X�ח� Lr����'t�j�q��[�,��L��8 7�p���[�Ek2��l_�" string(41) "Ready your ammunition; we attack at dawn."
Output for hhvm-3.15.4
string(32) "565047aed4cb031bc23c007cee9d1194" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "��PS�\dq3Av�W���s� �'] 4���2eo�6�QŪ���sտ������N" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.30
string(32) "9a4db0fdccdfc513a9c6bca198c70a23" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�X�_G�k ʥ[>��7�|f[k��PȨ��҇ gL+6l�ٌ�Sxƨ��Q�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.29
string(32) "60dcd4f2caed2c24fa31ab227676226e" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "��Ǹ��� �!xn��>P�{��Y��!���omjnl$A�� 0���as>OID��" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.28
string(32) "d5aa706aad4aef55b90703e7f6cf0c7f" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "z�\�j�=�}�Ƙ��`?�5��З�?�c����������^�:#�ލ�,���Yt�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.27
string(32) "e6dc6a3681fa8b967ee75066061b1946" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "5(�69�ӉAR�8gS���\L*^\E�¯�.��a7���o(�C��n���" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.26
string(32) "8e94aa47732954933556dcde3a6a3230" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�}7�7ϰ2Мo�u�kG[�5�!EĘ�����ߓ��o�ͭ�f��0[U�=@|:+" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.25
string(32) "8518a45692626494b87b26b883ef7d4e" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "E;%�S���>�ʣ�b����G}��ᘍ`�P��>;.� ֹC�!L&��a�Z�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.24
string(32) "512a4256773cc887a716d86544ae57b3" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "���;1�)vF��x�n�kd�`�J�!G��@S:��y��d���U�r���^D �@�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.23
string(32) "4ecb2cc9d6af6ed06049c7062d9ca9ae" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "`���RN�����hh��)�f�B�3�V��?���:���2I�U� U���a" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.22
string(32) "56baeb1e16a57c31ce17407778c182c0" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�‹���wl3��X�oc�b�3p�>��y�B�<�'�� �0-������Z˧�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.21
string(32) "c65aa65ec76837b2c1ca30b94caf41ac" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "��Z`ǰ(�b&��a`^���� ts��gg᳄�ې���H���&E=" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.20
string(32) "3d7e68698a818c408e6018e42c0f8c3c" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "��d5��>v�/hዐ�FD��j����8��Yn�lE�X��+|��Ё1h�%)�HΒ" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.19
string(32) "9b49b0122dd6dd0077665ab030b8deaf" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�AB�#߰�TEG��9�Eg�����4+r<�*�$�����h�o#���-��?b�1�S�\�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.18
string(32) "7161a6ccb100eea1b6a6cb2c847bf5bd" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�)��7�� �؎�d���vax�v;���cҖ�|��k���D�D����[��M�F" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.17
string(32) "af91c57d66551fbb17f17f15b9e3f5a5" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�7��LޣCu����p�1Aa�LwjzK3�6����]����c�2kchm֦" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.16
string(32) "1ba8d1280599232745b1565897cfc6ed" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "D��c.Bn]8B(��~;w}�!�� �y�#�x�/�}]p�e�a’Ȣ��}���"4� " string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.15
string(32) "93385bece7c150d82c9e0b3b7bbed32a" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�Hh� ������8u��9�qw>L�{_�b��C� ^#�erE��O~+z Bq��-�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.14
string(32) "336d0c1966a354da3615cca3f8dcafbf" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "����d$��E�^� g�9���ΨE}+ɦ���M�ɩ��m�1�V 孒�k<z��" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.13
string(32) "a8fc64bc3c7ad3eb29c14ae4d57849e6" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "WeZ�T��@��4K�4�1L�ܐE��>�g8u�褰�k�)l��=B������]UA˓" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.12
string(32) "311e11388a21c4ff8c2382d5232e7e64" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "���Kd�oL��M����9cݾə���/)V�=�����m <��HhZr�0���" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.11
string(32) "bfb4ec0c0a20a6de83529bc41b578da0" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�X��H��0]���~v������t�E^��� ��}���&����IM2���B�>�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.10
string(32) "acd6e5245ae9d0874089cb5678e6df2c" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�ƌ�h�۵���h2��l� �Q���h��Ҕ������mW��*��Yf� �k��" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.9
string(32) "2b717a3f1da6ad5a2ae766fdec1f01d7" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "g/� � CR����C�A��� V��#������ȃtokC�ir+w�?6!��" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.8
string(32) "5e941b33e83117d5032dd1bd9ffbd86c" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "������s^L�2.P�.��cMфNa����-m�[�~q��:�����#��F�� ~�" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.7
string(32) "0b13dab37daf6f9c69b1f2ca31d1841a" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "ܔ Hm��r���ޭX�(�pQ 8m5�L��yw� e�~J�c�J��,��5ߤ��" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.6
string(32) "974b04b792d6749550deb228491214e5" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "s�>%hnb��������1��o$�gȦԍ��S&�x�\��o�h�z��+���!x" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.5
string(32) "f6ae205880d52d0ab8c7bafb506cd5c4" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�s�]�+fh��a_]�6OŐ7%+(4-ak��@+�ߞ�'�L�GK��*�Փ�B" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.4
string(32) "b6cc2b57a4530217d7e1b936e2853e84" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�J��9����?B�V�&�@� *#�Vۀ��a�������wُ�:�M�e�oM�ī " string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.3
string(32) "908277a82706b001833ca77bdadbef1a" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�bj��ӟ-��iaŘA�׋�J(&�ܪ�껶|����̙���?9����?j" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.2
string(32) "a1216481b837997728f7cfdc7740a78e" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "�$�O�N+��;%԰IR��w�R>����[t�G�?_z����UŲy�z%�}�ő" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.1
string(32) "06280a8e0c5a0f42b970b324ed3cdffd" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) "q��GWOm�7�V�7p�)�֯K�%v��v4uE�=���^���X�ĺ��I��" string(41) "Ready your ammunition; we attack at dawn."
Output for 5.6.0
string(32) "66bc2c621d7454e48537b00cc4acf50c" Notice: Undefined variable: hex in /in/vsqNe on line 77 NULL string(57) " BĊ�����A�j�+�p�)��O��8P2��E���Q`�9����=�x����" string(41) "Ready your ammunition; we attack at dawn."