//
if (isset($_POST['getkey'])) {
    echo file_get_contents($PublicKeyFile);
    exit;
}
//
// The remote user is sending an encrypted AES key and iv to use for encrypting.
//
if (isset($_POST['key']) && isset($_POST['iv'])) {
    include $PrivateKeyFile;
    $rsa = new Crypt_RSA();
    $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
    $rsa->loadKey($PrivateRSAKey);
    $_SESSION['key'] = Base64UrlEncode($rsa->decrypt(Base64UrlDecode($_POST['key'])));
    $_SESSION['iv'] = Base64UrlEncode($rsa->decrypt(Base64UrlDecode($_POST['iv'])));
    SendEncryptedResponse("AES OK");
}
//
// The remote user is sending an AES encrypted message.
//
if (isset($_SESSION['key']) && isset($_SESSION['iv']) && isset($_POST['data'])) {
    $aes = new Crypt_AES(CRYPT_AES_MODE_CBC);
    $aes->setKeyLength(256);
    $aes->setKey(Base64UrlDecode($_SESSION['key']));
    $aes->setIV(Base64UrlDecode($_SESSION['iv']));
    $aes->enablePadding();
    // This is PKCS
    $AESMessage = $aes->decrypt(Base64UrlDecode($_POST['data']));
    //
    // The remote client is requesting that we end the connection and destroy the session variables (the keys).
    //
Example #2
0
$PublicKeyFile = "public.crt";
include "secure.php";
if ($AESMessage != "") {
    // Get the username and high score from the message that was sent
    $split = explode(",", $AESMessage);
    $username = $split[0];
    $score = $split[1];
    $rank = "";
    if ($score < 100) {
        $rank = "Loser!";
    } else {
        if ($score < 1000) {
            $rank = "Not bad...";
        } else {
            if ($score < 10000) {
                $rank = "Pretty Good.";
            } else {
                if ($score < 100000) {
                    $rank = "Amazing!";
                } else {
                    if ($score < 1000000) {
                        $rank = "~YOU DA BOMB~";
                    } else {
                        $rank = "YOU ARE A GRAND MASTER!";
                    }
                }
            }
        }
    }
    SendEncryptedResponse("Name: " . $username . " Rank: " . $rank);
}
Example #3
0
<?php

//
// Copyright (c) 2011 Scott Clayton
//
// This file is part of the C# to PHP Encryption Library.
//
// The C# to PHP Encryption Library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The C# to PHP Encryption Library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with the C# to PHP Encryption Library.  If not, see <http://www.gnu.org/licenses/>.
//
// Set the location to the public and private keys
$PrivateKeyFile = "private.php";
$PublicKeyFile = "public.crt";
include "secure.php";
if ($AESMessage != "") {
    SendEncryptedResponse("Got: " . $AESMessage . ", GOOD!");
}