I need to send a request from a php server to a .NET one.
This request have to be cypted, so I thought about
- Serializing the params
- Cypting
- Base64 encode to put it as HTTP request
Here how I would do in php
$url = 'http://my.server.net';
$params = array('var1' => 5, 'var2' => 'machin', 'var3' => 'chose');
$serialized = json_encode($params);
$crypted = encrypt($serialized, $salt);
$request = $url.'?'.base64_encode($crypted);
encrypt() would encrypt the serialized params with flavoring.
Questions are
- Which functions should I use to encrypt my message for it to be
easily decrypted with .net ? - Is json a good serialization choice for .net ?
I know nothing about .net, that will be done by other guys
For question one
PHP side I think you can use the openssl extension of php http://php.net/manual/fr/book.openssl.php. It brings you a powerful API to do what you want.
.NET side You can have a look at http://msdn.microsoft.com/en-us/library/system.net.security.sslstream.aspx or http://www.dart.com/sockets-net-api-library.aspx
For question 2:
json is a good serialisation tool but a bit lossy as it is typeless.
So two solutions here :
you know that the .net application will share the same class architecture as yours so using
serialize()is good.you do not know that or you know that it will be developped other way so json_encode is the best way to do that. I just want to point out the fact that if you five it as GET you will be limited to 255 chars instead of infinite if you chose a POST request.
Moreover you have to urlencode your json datas if you want them to be readable
To send a POST request instead of a GET you can have a look at this script :
http://www.jonasjohn.de/snippets/php/post-request.htm