0

I have built an API in PHP with Zend Framework 1.x For now there was only a webclient connecting to the API but we started developing a C# client. I am experiencing an issue, here is how it works :

  • User fills the form in the C# client
  • C# sends the data with WebClient.UploadValues (Some values are added such as hmac of the parameteds, x-api-key, etc).
  • The server receives the data
  • The serveur converts the data to a json and creates the hmac from it
  • The server compares the hmac sent and the hmac created

Here is where my problem is. Everything works fine if I send datawithout accents. But if there are, the Zend_Json::encode($params) returns a json encoded in UTF8 so the hmac created is not the same as the one sent.

So, I am wondering (as for some mysterious reason utf8_decode($json) does not work, should I find a way to compare the utf8 decoded json hmac of should I as the C# client to send all the parameters encoded in utf8 ?

4

1 回答 1

1

The C# client should send all parameters encoded in UTF8. You cannot run way from Unicode - UTF8 in JSON since the definition of JSON states:

JSON text SHALL be encoded in Unicode. The default encoding is UTF-8.

It could also be UTF-16 (BE or LE) or UTF-32 (BE or LE).

If you generate JSON from the data and then get the hmac there should be a difference, right? Since at the least JSON has two more symbols? { or } so should the hash be different than the one sent by the C# Client?

Either have the client send you the data in JSON or get the hmac before converting the data.

于 2013-09-16T08:50:51.103 回答