0

Hello I have been trying to make simple encryption with AES128 between app in C# and PHP, and it worked well quite well yesterday. I got like max 10% unencrypted data but now I got a maybe 90% unencrypted/unencoded/incomplete data. I am sure its because of the "special" charactes in these strings. I am sure it breaks the string into more strings and then it reads just part of it for example this

"/" or "+"

seems to break it every time and I cant remove these characters because it will break everything. I have tried something like this

$test = base64_decode(addslashes($StringEncodedBase64));

in hopes that it will hold the string together but I think it didnt help much if at all. I think only improvement was yesterday when I had The string encoded with base64 maybe 3-4 times atleast basically every step ended with base64 encode so i would get a nice hash in the end. But I dont want that because its nonsense performance wise pretty much and there is still some % data lost and more importantly I think it was because I used a weak key. Maybe yesterday when I was testing it I had better success ratio because I had very simple key like

1234567890123456

I have changed the key and the new is more complicated like

Omb1AH02AsuUACfu

is it why it produces these complicated broken strings? For IV I use random strings without numbers like

IHZWGhoxZoIugQmY

In the end of this logfile is one luckily decrypted message. On the lines above are the other 90%. I also thought about converting the these special characters into byte[] but the mcrypt_decrypt want a string and I also need it to return me a string after all. Thanks for any input

[08-Jun-2016 10:30:44 Europe/Moscow] Encoded base64:
[08-Jun-2016 10:30:44 Europe/Moscow]  NbqJie6PRQQtTMOzVFFCam4JcrheQQVvcS5kL5T7rBJqMcIZlqrZ8ZCip7vFqSX2g3c6Vf2KuG/ AQIWl9aDcNQFxFAfD5 C7reP8TttQK8GSp9S5A2VoJysxuyZOr2QpBZZIw07Kvfc2vilm ukqQebbEqxeQKeWlAX MjTnI=
[08-Jun-2016 10:30:44 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:30:44 Europe/Moscow] Decoded base64:
[08-Jun-2016 10:30:44 Europe/Moscow] 5ş‰‰îŹE-LĂłTQBjn  r¸^Aoq.d/”ű¬j1–ŞŮń˘§»Ĺ©%öw:UýЏoŔ@…Ąő Ü5qĂä.ëx˙¶Ô
đd©ő.@ŮZ    ĘĚnÉ“«Ů
Ae’0Ó˛Ż}ÍŻŠY®’¤m±*Ĺä
yi@\ČÓś
[08-Jun-2016 10:30:44 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:30:44 Europe/Moscow] Decrypt AES128:
[08-Jun-2016 10:30:44 Europe/Moscow] W;
[08-Jun-2016 10:30:44 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:30:51 Europe/Moscow] Encoded base64:
[08-Jun-2016 10:30:51 Europe/Moscow] bLExr70FXbpbNqbws1kGNqdFAWY/2E4FJaytw7FYBNQlaz5610QcW17B3I2 x7gYMxz4ZM6RVWxZOYaUyDrtUJsFgER0zDP5F/RPhcL1tRrVbv4bPdYmkoOQ8ZunHkJmfHbLocoMhzA286o acEABsV/ITe8v7qbWD9JxOiPfCY=
[08-Jun-2016 10:30:51 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:30:51 Europe/Moscow] Decoded base64:
[08-Jun-2016 10:30:51 Europe/Moscow] 
[08-Jun-2016 10:30:51 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:30:51 Europe/Moscow] Decrypt AES128:
[08-Jun-2016 10:30:51 Europe/Moscow] 
[08-Jun-2016 10:30:51 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:30:57 Europe/Moscow] Encoded base64:
[08-Jun-2016 10:30:57 Europe/Moscow] IzLBNSV5/xFuoezSFjrM4cIvz/m4woTUabL/qiR/7mk1LZyJyWmtgNjsp2fjvXOxC57sFGFiXPtHMWNiHSV23inmlI 7SqT9TnA/UiVxY5Gta7QVIzHBqpfl2jHBSf1yFcMLLq0DTinT6ZQ/gb9AOmo3PiaPQeSYcKHg3X7cAe4=
[08-Jun-2016 10:30:57 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:30:57 Europe/Moscow] Decoded base64:
[08-Jun-2016 10:30:57 Europe/Moscow] #2Á5%y˙nˇěŇ:ĚáÂ/Ďů¸Â„Ôi˛˙Ş$îi5-ś‰Éi­€Řě§gă˝s±žěab\űG1cb%vŢ)攎ҩ?SśÔ‰\XäkZíHĚpjĄůvŚpR\…pÂË«@ÓŠtúeŕoĐšŤĎ‰ŁĐy&(x7_·
[08-Jun-2016 10:30:57 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:30:57 Europe/Moscow] Decrypt AES128:
[08-Jun-2016 10:30:57 Europe/Moscow] I Would really like to get all my data 
[08-Jun-2016 10:30:57 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:31:04 Europe/Moscow] Encoded base64:
[08-Jun-2016 10:31:04 Europe/Moscow] In0p0Wjo5wjAkBGYa1/cCUA7YVHrePSJR983WPMO8xRAfpYUrixWDcDXvBcN0D34M1rLgG8fJxSUJhQ72NSqX4w78W62PBbqxR9B1I/qCZmICGsbxyK0i0Fl/uV1EOtl1RS7nckfDVytW2tfPDUk5wzvc RGxjUOna/jliKRH1A=
[08-Jun-2016 10:31:04 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:31:04 Europe/Moscow] Decoded base64:
[08-Jun-2016 10:31:04 Europe/Moscow] "})ŃhčçŔk_Ü    @;aQëxô‰Gß7Xóó@~–®,V
Ŕ׼
Đ=ř3ZË€o'”&;ŘÔŞ_Ś;ńn¶<ęĹAÔŹę   ™kÇ"´‹AeţĺuëeŐ»ťÉ
\­[k_<5$çďq±ŤC§křĺ¤GÔ
[08-Jun-2016 10:31:04 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:31:04 Europe/Moscow] Decrypt AES128:
[08-Jun-2016 10:31:04 Europe/Moscow] I Would really like to get 
[08-Jun-2016 10:31:04 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:31:11 Europe/Moscow] Encoded base64:
[08-Jun-2016 10:31:11 Europe/Moscow] OCPovKfyxdxpLxHed6twwJtKUTEhHVQ0cnJqrLs5yufLt9Mejn3zXanYkvDnNmbQJdFfCwSokRneAkrVKKmJJaFWhH/d2vfy6dC5FhKUNyS3SO2COMG9rHaunJG/SUNMaN9Le31KnVGgrxE cnnTPoC2EvUiFCe7umeW4AgydE0=
[08-Jun-2016 10:31:11 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:31:11 Europe/Moscow] Decoded base64:
[08-Jun-2016 10:31:11 Europe/Moscow] 8#輧ňĹÜi/Ţw«pŔ›JQ1!T4rrj¬»9ĘçË·ÓŽ}ó]©Ř’đç6fĐ%Ń_¨‘ŢJŐ(©‰%ˇV„ÝÚ÷ňéĐą”7$·Hí‚8Á˝¬v®ś‘żICLhßK{}JťQ ŻžtĎ -„˝H…  îî™ĺ¸ť
[08-Jun-2016 10:31:11 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:31:11 Europe/Moscow] Decrypt AES128:
[08-Jun-2016 10:31:11 Europe/Moscow] 
[08-Jun-2016 10:31:11 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:31:17 Europe/Moscow] Encoded base64:
[08-Jun-2016 10:31:17 Europe/Moscow] KG91J7FhmzaNTrtJvRScQv9ogBtGmdMZO8vZAFj9pAdlQ5NQf9M0WE0g3ZBb2SnV91WanLt1DePmx64vnKRqeHA2c4ty92L00REVpAj5apO4Z9aDQDIhh23AyPQ3ojsoZE6ckDcSaNprERyK4SjKYBTazlwKHPKMc7ZgrnB4qnM=
[08-Jun-2016 10:31:17 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:31:17 Europe/Moscow] Decoded base64:
[08-Jun-2016 10:31:17 Europe/Moscow] (ou'±a›6ŤN»I˝śB˙h€F™Ó;ËŮ
[08-Jun-2016 10:31:17 Europe/Moscow] ----------------------------------------------------------
[08-Jun-2016 10:31:17 Europe/Moscow] Decrypt AES128:
[08-Jun-2016 10:31:17 Europe/Moscow] I Would really like to get all my data out :) D6BAB3086E9CA53E5848A4006C8F2610 1465371072
[08-Jun-2016 10:31:17 Europe/Moscow] ----------------------------------------------------------
  • Are you reading from file, database, $_POST or $_GET ? – Roland Starke Jun 08 '16 at 08:34
  • 1
    you need to escape it: if i read http://stackoverflow.com/questions/86477/does-c-sharp-have-an-equivalent-to-javascripts-encodeuricomponent corectly u need to use `"http://server.bla/file.php?data=" + Uri.EscapeDataString(data)` – Roland Starke Jun 08 '16 at 09:00
  • There is no problem with url it can be read without problem by $_GET example Get request: `"GET /report/?nick=Userman&server=MyServer&data=J7YTQR3TUDF5OTW0Zfb+eZh3Is6slZsa1jYB0B+FOjBsLZp3X0OJPAhgjTD1f5Lss1pYHy3UFM3B5Dyuw+sCJdcixDdlU6xWx7ahqDfJ1GUft5IUIMl9527FeEEDrJfR1hWPoSzj9hdplT5nrv0SzB/iMo9USKUuVdKDGQyWuCkWCv1py0AGqqvfKrk= HTTP/1.1" 200 3 "-" "-"` There is some problem with errorlog console on webserver it cant read "+" I would like to escape these chars in php after I receive the data. – I hate my brain sometimes.. Jun 08 '16 at 09:18
  • your request url should look something like: `data=J7YTQR3TUDF5OTW0Zfb%2BeZh3Is6slZsa1jYB0%E2%80%8C%E2%80%8BB%2BFOjBsLZp3X0OJPAhgjTD1f5Lss1pYHy3UFM3B5Dyuw%2BsCJdcixDdlU6xWx7ahqDfJ1GUft5IUIMl952%E2%80%8C%E2%80%8B7FeEEDrJfR1hWPoSzj9hdplT5nrv0SzB%2FiMo9USKUuVdKDGQyWuCkWCv1py0AGqqvfKrk%3D` – Roland Starke Jun 08 '16 at 09:50
  • Yes thank you I understand now I tried to encode it with base64 again two times more and it looked clean as URL but after decoding it back it was just the same mess. On the other hand `Uri.EscapeDataString(data)` works absolutely flawless now I cant undertand how it could work so well yesterday without it but that doesnt matter. – I hate my brain sometimes.. Jun 08 '16 at 09:55

0 Answers0