base64_decode() returns different results in different PHP versions - character-encoding

For this base64 encoded string "Q8Ju/Mbi4UDGBt2aqXhG7Q=="
PHP 5.5 and lower returns this: CÂnüÆâá#ÆÝš©xFí
PHP 5.6 and higher returns this: C�n����#�ݚ�xF�
It appears to be a difference in how the function handles character encoding, but I can't find any documentation on it. I recently upgraded to a server using the latest version of PHP and encountered this error with data being sent to me, that I am not encoding. So using PHP 7, I need to be able to to decrypt the strings I am receiving to get the same result as PHP 5.5 and earlier.

Related

Could not decode based64-encoded string by System.Convert.ToBase64String

I am encountering an issue about based64 encode/decode for an image.
My iOS client downloads a string, which is a based64-encoded image on the server side by an API named System.Convert.ToBase64String.(dotnet)
However, some pictures could not be decoded on the client side by NSData.initWithBase64EncodedString. It always returns nil.
I have tried the same based64-encoded string on Android and some tools on the web, all works fine.
I have no idea how to debug this issue to figure out which byte causes this problem.
Any idea?

AppMobi fails json parsing on iOS

I am developing a mobile app with the AppMobi tools and xdk. If I make a call to (accepts POST only) http://mg.smartmax.com/sightmaxwebservices/sightmaxwebservice.svc/jsoperator/TestjqMobi
The returned json fails parsing on iOS only (android works fine). This same call works fine in mobile safari, but it seems when its called from the app, it takes a different path and errors. This seems to be a known issue and was wondering if anyone had a good workaround?
I work at appMobi - this appears to be a bug with the native container in iOS. Have you tried building your app and testing (app*lab doesn't have the latest code base).
What are you using to parse the JSON? Something like
var obj = JSON.parse(data);
As a workaround for now I suppose you could just include and use another parser.
Make sure that your server is properly encoding the JSON.
I ran into this exact same issue. If you are using Drupal as your backend, use their function drupal_json_encode instead of PHP's json_encode. The information I was passing to the app was generated by a WYSYWIG editor, and perhaps that is what drupal's json encoding function takes into account that php's json encoding doesn't.

iOS NSJSONSerialization returning null

The App that I'm working on requires to parse a very big Json file (17.5 MB or 17mil characters).
I have coded and tested the App using smaller Json file and was successful doing the parsing, Only when I test using that 17.5 MB file it returns me null object.
I'm using iOS 5.1 and used JSON reader API of iOS 5.0 as well as JSONKIT which both return the same response, NULL.
Any advice would be highly appreciated
Thanks
If it is really a size problem you might break it into pieces on some natural boundaries. I have done that with large xml files in the past with good results.
But as #Alladinian mentions in the comments do verify that it is a valid JSON file.
fwiw, i recently uncovered a bug where NSJSONSerialization fails when the JSON file being parsed is > 32k in size. when we trimmed the source JSON down, the same code path works just fine.

FileReference.upload fails to post multipart form with additional unicode parameters properly

I am in a Flex 4.0 project attempting to POST to a Java servlet using FileReference.upload(). I am sending some additional parameters such as album name in the POST. This works fine when the characters are in the Latin1 character set. When I try to post a Japanese character or some Unicode character, it doesn't come through on the Java side.
FileReference.upload() ignores the content-type setting and uses a Content-Type of multipart/form-data by default. I do not know what the default encoding is in this case. It appears that it is not UTF-8.
On the java side, httpServletRequest.getCharacterEncoding() shows null. The method is POST but I can't confirm how the data is being encoded.
So the problem is that I seem to be stuck using FileReference.upload() because the user is picking the file to upload. I need to send Unicode but I can't get Flash to encode them properly. Not sure if using URLLoader would help or if I can even get the data out of FileReference into URLLoader (and then lose progress events).
There is no need to deal with server.xml. All you need to do is to set requests character set to UTF-8 in the servlet.
request.setCharacterEncoding("UTF-8");
So the answer had to do with the Java side and not the Flex side. I had to add URIEncoding="UTF-8" in my Tomcat server.xml to my connector for ports 8080 and 8443. That is what was needed to pass the unicode values. Then I had to ensure my datasource (SQL Server) was set to use sendStringParametersAsUnicode=true. Now I am able to post unicode from the Flex app to the Java app and save it in the database.

How to upgrade an MSXML Document from version 1 to verison 6?

My application uses MSXML version 1 (MSXML.DOMDocument) to store user documents in XML format.
I want to upgrade to MSXML6 (Msxml2.DOMDocument.6.0). The problem is that old documents are not always readable with the new version.
The cause of this is that the old MSXML parser does not correctly encodes non-Latin character as UTF-8, and the new parser refuses to load these document.
My question - how can I read / convert my customers' existing files to be readable in MSXML6?
It is really a good idea to fix those old xml files with correct encoding. In fact, a W3C conformant xml parser is expected to choke when handling this kind of xml files.
As far as I know, MSXML does not provide functionality to fix the encoding for old xml files.
To fix the encoding, you can do it manually with Notepad++ (choose the actual encoding, and then convert to utf-8), or convert programmatically if you are sure of the original encoding, e.g. ANSI in your case. There should be いろいろ sample codes over the internet.

Resources