If you use the wss: // and https: // protocols, you do not need to worry about the man in an average attack, since all the data sent is encrypted anyway.
However, if you have to send data using an unsafe protocol or a query string for a URL, you can encrypt the data yourself using the PHP open PHP module and send it in plain text (for example: $ _ GET params).
Example: http://php.net/manual/en/book.openssl.php#91210
In this example, $crypttext will be binary data. This can be encoded into a base64 string and the URL encoded if you need to send it via a GET or POST request.
urlencode(base64_encode($crypttext))
On the receiving side, you can decode base64 and decrypt the url to get binary information, and then decrypt the data using the private key, as shown in the example.
base64_decode(urldecode($crypttext)
source share