Downloads
Here are 3 downloads necessary to use AJAXRSA with Construct 2 :
Plugin Construct 2
Download, dezip and put the folder called «ajaxrsa».
in the Construct 2 Plugin folder.
(size: 10 Ko)
DownloadPlugin Construct 2
PHP Library and Demo
Download and dezip the folder.
You will obtain 2 folders et 1 example script.
(size: 143 Ko)
DownloadPHP Library & Demo
RSA Keys
In first, you will need two keys : Public Key and Private Key
Launch the RSA Keys Generator (search an executable called «index.exe»).
You get this :

Construct 2 Plugin
Make sure your folder «ajaxrsa» is present in the Construct 2 Plugins folder.
C:/Program Files/Construct 2/exporters/html5/plugins/ajaxrsa/

Launch Construct 2, create a new project, add new object : AJAX-RSA.

Now, open your Event Sheet to add the following Events/Actions :

PHP Library & Demo
On server side, make sure your folders «Crypt» and «Math» are in the same folder.
Below, the demo script to process the data server side:
ini_set("display_errors", 0);
session_start();
require_once('Crypt/RSA.php');
define("KEY_PRIVATE", "-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBAMrXPEVu4LxhOUvV2mreOoHIchPlJYgvRdpqkBd6t2sD7SM02DqP
n89eSj+oqG1ZR+l7Yj1SMCZMrav6257UivMCAwEAAQJAHHwerKl7dI46sO72iJdt
+UJ1iAcKlECp5e2dD+Rd1EXYNfIH26AyprDRXNTRoTYidiVaUH1Z8NxifWagf36j
gQIhAOKOTxjSwgDIWQxoMxw2AL8AAGF3g4uWXgRZKp4f9QghAiEA5TPn1H/j7AQW
NTW7WmM6PjV/Xdl0YI4y2OUTdw2E4JMCIQCvYFJCeQPM70pfnFnUQMmbETk6OfYO
nDvzScL/3OUlgQIgZop6RU+SIJ0Tcmq/jwilnf9BJDONJUV46iBSPQkHUZECIAnE
byHHtgYokdOrheh+O1FWUtq5q/xq28TR+tHUFa1i
-----END RSA PRIVATE KEY-----");
function decrypt($data) {
$rsa = new Crypt_RSA();
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$rsa->loadKey(KEY_PRIVATE, CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
$s = new Math_BigInteger($data, 16);
return $rsa->decrypt($s->toBytes());
}
$arr_data = array();
if(isset($_SERVER['HTTP_REFERER'])
&& ($_SERVER['HTTP_REFERER']=="http://www.payondev.fr/projet/ajaxrsa/demonstration/"
|| $_SERVER['HTTP_REFERER']=="http://www.payondev.fr/projet/ajaxrsa/demonstration/index.html"))
{
if(isset($HTTP_POST_VARS[d])) $data = $HTTP_POST_VARS[d];
if(isset($HTTP_GET_VARS[d])) $data = $HTTP_GET_VARS[d];
if(trim($data, " \t\n\r")!="")
{
$decrypted_data = utf8_decode(decrypt($data));
parse_str($decrypted_data, $arr_data);
if(isset($arr_data['token']) && trim($arr_data['token'], " \t\n\r")!="")
{
if( ($k = array_search($arr_data['token'], $_SESSION['token'])) !== FALSE )
{
unset($_SESSION['token'][$k]);
$expiration = explode("_", $arr_data['token']);
$delayToken = time() - $expiration[1];
if($delayToken<=2)
{
foreach($arr_data as $key => $value) echo $key .": ". $value." ";
}else{ echo "Error : Token Expired"; }
}else{ echo "Error : Invalid Token"; }
}else{ echo "Error : Token missing"; }
}else{
$token = md5(rand(1000, 999999));
echo $_SESSION['token'][] = $token."_".time();
}
}else{ echo "Error : It's not a call from the game"; }
Of course, the use of Tokens (either side Construct 2 or PHP) is not mandatory but recommended for browser games.