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; } } $message = 'Ready your ammunition; we attack at dawn.'; $key = hex2bin('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'); $encrypted = UnsafeCrypto::encrypt($message, $key); $decrypted = UnsafeCrypto::decrypt($encrypted, $key); print_r($encrypted); //var_dump($encrypted, $decrypted);
based on jl7qR
Output for 7.2.6
Fatal error: Uncaught Error: Call to undefined function openssl_cipher_iv_length() in /in/CHPMk:21 Stack trace: #0 /in/CHPMk(76): UnsafeCrypto::encrypt('Ready your ammu...', '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\v\f\r\x0E...') #1 {main} thrown in /in/CHPMk on line 21
Process exited with code 255.
Output for 7.2.0
��v�)���k`���"�d�0�z��ͭ5�l � 8SEW[$R��a4���p�
Output for 7.1.10
t��12a�χy���!�@�URT&ih��'�;?9���V?�`��l�']/��tOԭ
Output for 7.1.7
Θ���ԕ x���V���]�!�o����_ y�� )$��.�A��k�2S4��
Output for 7.1.6
�A^��U�=%��&��x<s�W�3��� `(��EX�3�d_8��Z�fy�P߁7
Output for 7.1.5
��K�g�w�w�h�C_��=ѐ��2�m=��CӞ���i�#R.\,=�|��i��
Output for 7.1.4
�3`��(�E�2%l�a�Ě]�y<�es�M���d�_����$�xY�}���ec��
Output for 7.1.3
-�����@$��Xp𱣈�o���K�ST:����h �4�o�k\��l���∝�
Output for 7.1.2
꾅jcL�G�x�]�X}w��6YW$G���,������IEG�H �lcY��Έ�8
Output for 7.1.1
u�W@w��*^t�Ib�H�(��RT�.K�[4#pV�"��p� �q�����-��'
Output for 7.1.0
3�O�9`U�‘p�����Y�=4ݘ�n #.�v˅���%�%��v��>EC��T0Z�\$
Output for 7.0.20
������ѕ������n}P�pg�t*�����%V�� �7_!�9p[ۆ�D?{�$B
Output for 7.0.19
u��F�ˉv��G+5�Vg �B�&��tM�j�%Ws.I�\��( �*�:�m�]�� �
Output for 7.0.18
��Q�^��f,KM������~�fk]�ڎΚ��Ai�0���7&�5��s�(�
Output for 7.0.17
.v��sy��k�?"4����&ם�Q�yQ\�C�˿J#p��E�y�Ɲ�k���$a)�
Output for 7.0.16
�E��B�����Xd��x��$�6�%�q����ά"3��i,hl��:І��o�Tle
Output for 7.0.15
Nk��m^�A�G�..^ֿ�m��C�#��6��� V>�w�]�B�,�M��6Z
Output for 7.0.14
)�כ�$۹���˅I�L��O�:��XPOG'����7�"��+l���R
Output for 7.0.13
`R�e� A�SQE��A�t�z�aB�����^`�C� �A���-�3������$
Output for 7.0.12
��ڦT��L�J�7]�u�:_�J���ʒ�.��:V֑�1-���^�u��B�
Output for 7.0.11
6��"�q���ܫ��y(Sl��O'������ʣ�i�w@��!��Y$��[�yѲ�)
Output for 7.0.10
!zZ>�,��b7���{�iɾ�5�z�B��w���仛Dz4;��Q�A��;%��x��
Output for 7.0.9
�s�i����r�(8Y����E�f�Z��-��<'*��8���gm$�� tA6R��
Output for 7.0.8
楁����-���k�.l����C�=�f��K7 X�w*�oۑ�`�Po��pV�R�
Output for 7.0.7
��mA�u�<ZD���u �GսQ�1oY�[EkB���h���u��~�U;F{��8��obwH
Output for 7.0.6
�Y��g;+o[b36D������ �, �����69�yp�(a9 �q�^� �
Output for 7.0.5
}O��pT��x��w�9���` 2O9��>��3��(�~L�l�`��٭�n:�r��ȧ��
Output for 7.0.4
����.mg�;W��œ�t\��z�R^�!�˛)��3�:Hi��7��ڱ�'
Output for 7.0.3
���� D' �M#3��<^�g�)���tk���<�77s�9��W �T�|f�ڭ��a7
Output for 7.0.2
֜�y4$�KU��s���Ŕ���F�� ��U��mTM$�^=��Hʺ����s�r�
Output for 7.0.1
���6x�兣����O-Fx�fI;��{�@S��CX��NJeѴ��” �?�ӻ�f�u
Output for 7.0.0
c��&�BS���f]��� \���$��y�[�P�8n��Qg���c�i�d��7�|�
Output for hhvm-3.17.3
HW������4Ni� �rK �����V"��mhe���;�� <:varb~ �����
Output for hhvm-3.15.4
J� �,�-|+���y����ϩ(�t$��DX @i.������a�g���R"��I�
Output for hhvm-3.13.2
ĤO/�kw��������Q�J�Y��5Ef��g�_ƾ=�<q<!Q���/
Output for hhvm-3.12.14
�?�C��Kd6V���#���N�X�PL)8$غ�9=����&����Ϣ�큁3��_t
Output for hhvm-3.11.1
"�T�g�����q3�N��c��9.�w||�:��Bq�s���9���7��f�4�~
Output for hhvm-3.10.1
��C����=0�����A�WT�`E����T�d��N���� �\��-�6��?
Output for 5.6.30
�C8 -��Ӣ�D%v}g^},3&�Skg{*�a�sf�V��@Y�#���@ � l�T��
Output for 5.6.29
��ȃ�@�a�&^}�!����]{噋,�48۩�N�����ܡ��� �VͲuZ��4
Output for 5.6.28
�*Nt��6�͏r�(����h��*�3a�y�#���T/4�>� �Y�WH�
Output for 5.6.27
h>7 � � U<�}ch�q���HiP��d ���HJP��/�SY������c.nb
Output for 5.6.26
�Z�'ߡI�~;*�7�~ ���1 �P�8Ht�� ���X�� F���F�P }�|���Y�D
Output for 5.6.25
ڜ�0��As�}"S��m�)LR��e�n� �a�R'Э!�A�ن�S�qh��4v���
Output for 5.6.24
W�փ�ľ��(`N�kמ:ӥB�y]�T���� �>kr���?��b���ъ�͂
Output for 5.6.23
<��C5Һ'�Xαsc�� �ф-B�1�꡼�br�j�縃>����~��JE2��Vo
Output for 5.6.22
9�B������_������q�ט[���#�T����_�yh0Rp��xÈky�}��
Output for 5.6.21
R���y��=<K�~��b����=�I<W��`|�3pk�2#jv)��4<��e^凟�I
Output for 5.6.20
�^�<,d�P��S�?ӳFj�'���OB�O�d���uhD�,?E�}e��-/ �c
Output for 5.6.19
h��M�9x�{��u�)��6�3�%�*��hx���$�r�]8�My-�κ �9�����
Output for 5.6.18
m�r�z��C�[BL�z^��u�a��۰6,�������� ~��ԝ�e�%�
Output for 5.6.17
n��mտ�%,ǡ��[�U�k�2�cLy�6qv�?a�"�%$h�p�mz#^]���
Output for 5.6.16
��vw8��,�H��f��vKT-Sa�^0C�^,ڕ�[��\�Pϝ$���$aT�4�0��"Y��
Output for 5.6.15
MW(��ZqXMG��e��E"� ���Zr/�$�6[�%_l�qP=E�~���l�
Output for 5.6.14
nˊ�����:�Ȍ��fu�-6�J��W�d�x�r�� �Ѿ]S�@�]~��ʼ��>N��
Output for 5.6.13
��N���y|c��>���Ҝ"��;g�/1��O��B�WS�"��6X�S33��$Ys!�M
Output for 5.6.12
��W/U�j���ɰr��.M��ți�hz��u��-Sv��M�w�^zjZ{������K�!
Output for 5.6.11
���l\�$ou �k��g^���� .2 k�J/��Y��D��Eڪ��Z��);f
Output for 5.6.10
s�+�q�^�Q�7��R�n˯)@I̕���m=���6�����7�b�
Output for 5.6.9
�YcO�f��[cotFg��HG�������Ϙ�H70�4��ANP��gW��J�P�-,�
Output for 5.6.8
ә��V�q�(o�� ��^+1�m ���?��]�n˰�Z?���У����cp���
Output for 5.6.7
k�%�׵�Hk:Zu#� S�K�k�A�U��uf�m�SE�n��R�̓����^N�
Output for 5.6.6
����{5�E~C�ۄr�@Rx}�r���������N����^��]A=/�>
Output for 5.6.5
�Z0��H5ؒ�C�q(���e�Svi8�P4��{�M��zd2�Ad�=>k-˱=�W�(X
Output for 5.6.4
lcf��,���O��b]d��o�)IO�t鶋#U ��ܘd�=J��V�ͯ
Output for 5.6.3
�R!"��R��"����9m��9=��f/>�f�=q��u��J![���W�xݶiƂ<�
Output for 5.6.2
Z��)��<� \)SC:юH��z6� ��B|�ݑݑ(� 4��� �y~r}
Output for 5.6.1
�m�Q� �ťD�7��J��o%�//pv]��=�B���]���� �g 6�����.
Output for 5.6.0
�˻>�����O�ɉ<��?�MXjp��m&鴾��n�q�;u�p�c�:3^M �Y9J�
Output for 5.5.38
2����h�ޥ$�i ��8����u�b�L�r " �]W�a�1 ,V�9���� �
Output for 5.5.37
��C<��m$A�c�i�{+(�� y���j�k���g� :.8�eI�V�˥?`Z�\���
Output for 5.5.36
p$�R�M���߽��D^}�?춠����˜L��Y�ڗ� ��pg��;U���E
Output for 5.5.35
=�S�f*��� 9{>����,d`5i�U9�J}4��Ww��}�&-Dߔ��W
Output for 5.5.34
�_ӿ�D��U�s� ��Q&�)��f� �_VQ�\���K��0q�D�,�<Ƹ���
Output for 5.5.33
�5H��oz�`�0�_��������� �H�Fm~6Ү�nn��֕G��#�0xL����@�
Output for 5.5.32
���UYj�Y�ۖ_'��� �F&d�����^�+�˛��`�E|׎y!pU��r/�
Output for 5.5.31
f�F9j�γ��� �C_�Ř�P����d�����gr�� !5�E�<Iˑ#�b\
Output for 5.5.30
ː�.�&��O�*:zw�c�.��Y��h=gۺȹ�#'N��� Qh�t���P�
Output for 5.5.29
���U��=vu�j{O <u���I��/���}�:c�)n�#������e8 �֝��:
Output for 5.5.28
8�����T�pZnR�Dk�� �^}���,��P��ֱT��<��{�#
Output for 5.5.27
Y�K'��<�'%��<��Sk��w&{g����`�>�����$�jWK0����v%��
Output for 5.5.26
@A���H�$��w�%x�<� �:�y˄� �T��G�j��hs��D"���6'jOu%[
Output for 5.5.25
���h�y�A��� �,kg���� i�Q��4 �l�lEiӺ>MG�A��Kn
Output for 5.5.24
��Rt>E�.$+�=�ӓ�S ,�">L����J�t������t��� $�"^�=W
Output for 5.5.23
x�����d��UnF����j��J���ӈueyB�,7'��ǁga���U`pε
Output for 5.5.22
��۩K-&�No\�b��gս��8�¹\�, �E (��r�82�v�->�P��a�
Output for 5.5.21
�Z�b�<�<�r9Q2�&���]�a_FI��D�X1�̣!���QO�r��9��"}�d3sO�
Output for 5.5.20
Yu��S�^mIy_�)�\�?bnT*)V��Y��k�S���;3L�@7�Z�=
Output for 5.5.19
%��֥��D}�����k�� ��9u�R@j��s�ؑW2Lv�ϧ�g_�G�^dq�
Output for 5.5.18
�<�oZaoQ�u��c!�^'�>/W��l9oh�CCF�}I!.c��?@ c8�0���v��1�ip
Output for 5.5.16
�S�ٖP��!��1�a�h:���L^Ƥp�����*��)R�9��K-��"�(|
Output for 5.5.15
~�T*��!qߺUu��%X�;�� x�DΟ�v'Z�@^�#c��ۮ?8^d�p�k
Output for 5.5.14
S4s:������#�i����>�r� �����(��9�+ �hEd��O������{
Output for 5.5.13
����G��#~`8p�Ck��Z��ں��@�m��}C���+���ZCN�� o���Z�p
Output for 5.5.12
�r��������\L�R��xV���F����|���go 1�;���k� �q
Output for 5.5.11
���TF��{�촕u��GQ�*��41�͛/ !>�p7i<�Y�$\�"��#J�?
Output for 5.5.10
1Z;o ��� A���P)��\��}�RM�wq2����v�W�ԻԀv�)>|�I�d
Output for 5.5.9
Z���AC?-�ՠ�Z�K�f���a~�O��W@ƒ�IZ��Rh�3����;
Output for 5.5.8
k1Dp��� T��P�oϛ��S@1��U�S�P�餙9�Q&�֥��I
Output for 5.5.7
�l)pd�b�Yq�B��!��<�rj5�o^D�Pɴ�[�T�~} �L6d��N�BK}�
Output for 5.5.6
-[��EqG�d30Z�Y�/���U)�YE�FwtN),t�[/���,`w��l�`
Output for 5.5.5
��k͂vOw�K��聊1�o�셧g���Lu7�6,��7 =��E�Ө1�
Output for 5.5.4
ߗ:+jE M-�j;g�� -�h�̈́�ZZ.���\p���!9v�chD9$(� ���H
Output for 5.5.3
�a� h 0��o?R�?O��op�P1l<�5E�n�����{�' 3�=�+�j�¥
Output for 5.5.2
r �!����OkӵVտ,�;�s��93o`��U�\⮵$�9y��J�l�Qy�
Output for 5.5.1
m�w��R�])9T��³�Wf9⦩�g�*g�a �|hW-*G0���OK��� �3�3
Output for 5.5.0
�G�w*���ߘ� ,493]`�lb�x�{���U���(Ē"�m�V����k�
Output for 5.4.45
����4Qy�>��L?�۫�6�6�=?v8b�z�+���G�:���Y6 !�`�TOz
Output for 5.4.44
4�jz�,]π�D���k�CN�R��B�Ŋ^��mj���B7�G�hL�ҕ
Output for 5.4.43
��e�p�aC�nѣ�KVF�a0f���=-�ݜ�D�>eȣh���Y��PV3����{!
Output for 5.4.42
��HF$=/Kgn�[��͆����$�HU��n8�N�i�����-:����u�o�
Output for 5.4.41
�a`~c���i��H�D�5V�T�R���?Ef�������j���Ea� ��CT
Output for 5.4.40
J.�,3�N$�*Ӹ���A{z��$4�%A�X+{'Dž�"c�E�6�?���!�hD�
Output for 5.4.39
�o�1q��s�_��V��n�z���M+��*$�)>f{r�Hd�`W��M���I
Output for 5.4.38
T�U�vh�.ho� W����*zt�x�-UO���]�6�p�IޟRo���V[��+��
Output for 5.4.37
��o��!k��\�w' &V��P7�aʼn��b0I�~�o���W�n���]� �Ԓ
Output for 5.4.36
�n3 /�a���)_aw�4nr/�#O��Y��[�09�4�>qX��{2N���GOr�
Output for 5.4.35
��Q�%� �AȾ|j���*n@͠ OPt��D v�zBT�HP����#�D���9����J
Output for 5.4.34
��$�ے�g4v �c����q�z��:m��Թ�f ����S��u�6�V#ھ�m梟�
Output for 5.4.32
#�ÅC^�w�~����7�}����݊Ww�߻X��7��jR��a�8��������9 
Output for 5.4.31
��� ��3��I�]&$��I�i�*G$(����9u��� �z V��� �>�D�
Output for 5.4.30
� };4[B��!�b(��L/IK���>�Λ~�C&q|�C�V��k��x�8eN&K
Output for 5.4.29
�i����n�"B��h��?`gh�= ��2a+t�Ô Z�ZO��e�RB � v�Z�
Output for 5.4.28
N ����F�sx�./RF���F ��ik���j�/����*������cw��
Output for 5.4.27
���]�^`��)�M�5I�D�/6H �<zȱ� *sރ_ʹ[�����s=�K�\���
Output for 5.4.26
E�#cmK�,�C D ˟��񆔟�F�_��޸��)�����|,<r�"f趟 ��Ƕ�
Output for 5.4.25
tq���:mo씺ly{y���q�m,3,�����bB�,"�Ҹ�8C��uS2�I�
Output for 5.4.24
-��}At�b��_��ڮ�JK���ۂ��K��R ��r$��vw�,W,�O�ϛm��
Output for 5.4.23
ML���.��������_t8g?���FI���� I5{��Bx5�Tv�5�.�<*�i
Output for 5.4.22
��;RK%�O�|�M_/�U����$����4vd�1�w����m�)���92
Output for 5.4.21
��r� H����Rޖ2u���� �:w@�h�VS �{����k�"����
Output for 5.4.20
;�S�$9c�I��=+���J�����4�X�N:9"p)�9�;����B�U��w��
Output for 5.4.19
X ��B� ��l�m����oNz}��{��^�`�#Nm-�|�,t ����՛�n��5
Output for 5.4.18
��E���ɍ�-['9]�U���E )4���O�V�x%�ӳ��A�(�$&X�
Output for 5.4.17
A�j-��N��\����X*҉�L��=�dx�z��\��,�����C��k�W��
Output for 5.4.16
=ׂ3��O��v�d=�Т[�x���T� Y+\~2�}7:�5�L��Dr \NV��*�� ���
Output for 5.4.15
��=��^OR��O���ҧ��Hʧ���޴�RzC%F�5ˑ�e�UC�'�&�R�>
Output for 5.4.0 - 5.4.14
Fatal error: Call to undefined function openssl_cipher_iv_length() in /in/CHPMk on line 21
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.1 - 5.3.29
Fatal error: Call to undefined function hex2bin() in /in/CHPMk on line 74
Process exited with code 255.
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/CHPMk on line 80
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/CHPMk on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/CHPMk on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/CHPMk on line 9
Process exited with code 255.