|  (FEITO) recebe a notificacao
                                                                  |  (FEITO) verifica se a assinatura da mensagem coincide com a do certificado da Alice 
                                                                  |  (FEITO) desincripta a chave AES com chave privada
                                                                  |  (FEITO) usa a chave AES para desincriptar a mensagem
                                                                  |          assina a mensagem
                                                                  |  (FEITO) opta por tornar a mensagem publica
                                                                  |
*/
/* IMPORTANTE PARA CONSEGUIR ESCREVER AS CHAVES E OS CERTIFICADOS O UTILIZADOR DO APACHE TEM DE TER AS PERMISSOES CORRETAS
   VER http://serverfault.com/questions/357108/what-permissions-should-my-website-files-folders-have-on-a-linux-webserver
*/
include 'Database.php';
include 'openSSL.php';
$database = new Database();
$openSSL_Bob = new openSSL();
$openSSL_Alice = new openSSL();
$message = "AINDA ESTOU A TESTAR";
$username_Alice = "ALICE1";
$password_Alice = "ALICE";
$username_Bob = "BOB1";
$password_Bob = "BOB";
//PRIMEIRA PARTE
echo " <h1>PARTE 1 </h1>";
//CRIACAO DO USER BOB
// chave de encriptacao da chave privada
$passphrase_Bob = 'PASSWORD USADA PARA ENCRIPTAR A CHAVE PRIVADA DO BOB';
//cria chave privada e certificado para o Bob
//"Distinguished Name" e necessario para a chave publica
$distinguishedName_Bob = array("countryName" => "US", "stateOrProvinceName" => "New York", "localityName" => "New York City", "organizationName" => "example.net", "organizationalUnitName" => "Pro PHP Security", "commonName" => "pps.safebook.com", "emailAddress" => "*****@*****.**");
$openSSL_Bob->makeKeys($distinguishedName_Bob, $passphrase_Bob);
//insere o Bob da Base de Dados
<html>
<body>

Welcome <?php 
echo $_POST["Username"];
?>
<br>
Your email address is: <?php 
echo $_POST["Password"];
?>

<?php 
// create a new openSSL object
include_once 'openSSL.php';
$openSSL = new openSSL();
// generate a keypair
$passphrase = 'This is a passphrase of reasonable length.';
// a "Distinguished Name" is required for the public key
$distinguishedName = array("countryName" => "US", "stateOrProvinceName" => "New York", "localityName" => "New York City", "organizationName" => "example.net", "organizationalUnitName" => "Pro PHP Security", "commonName" => "pps.example.net", "emailAddress" => "*****@*****.**");
$openSSL->makeKeys($distinguishedName, $passphrase);
$private = $openSSL->privateKey();
$public = $openSSL->certificate();
print "<h3>Key and Certificate Generation</h3>";
print "<p>Your certificate belongs to:<br />";
$openSSL->getCommonName() . "</p>";
print "<p>Distinguished Name:<br /><pre>";
print_r($openSSL->getDN(), 1) . "</pre></p>";
print "<p>Your private key is:<br /><pre>{$private}</pre></p>";
print "<p>Your public key is:<br /><pre>{$public}</pre></p>";
print "<p>Your certificate is signed by:<br />";
$openSSL->getCACommonName() . "</p>";