//insere a Alice da Base de Dados $database->insertUserDatabase($username_Alice, $password_Alice, $openSSL_Alice->getCertificateSerialNumber()); //FIM CRIACAO DO USER ALICE echo "<h4>registou a Alice </h4>"; echo " <h1>PARTE 2 </h1>"; //extrai a chave publica do Bob $public = $openSSL_Bob->certificate(); echo "<h4>extrai a chave publica do Bob </h4>"; //cria chave AES $AES_key = bin2hex(openssl_random_pseudo_bytes(12, $cstrong)); echo '<h4>cria chave AES </h4>"' . $AES_key . '"'; //encripta a mensagem com a chave AES $encrypted_message = $openSSL_Bob->encryptAES256($message, $AES_key); echo '<h4>encripta a mensagem com a chave AES </h4>"' . $encrypted_message . '"'; //encripta a chave AES com a chave publica do Bob $encrypted_AES_key = $openSSL_Bob->encrypt($AES_key); echo '<h4>encripta a chave AES com a chave publica do Bob </h4>"' . $encrypted_AES_key . '"'; //assina a mensagem com chave privada da Alice $mensagem_assinada = $openSSL_Alice->sign($encrypted_message, $passphrase_Alice); echo '<h4>assina a mensagem com chave privada da Alice </h4>"' . $mensagem_assinada . '"'; //notifica o bob $Bob = $database->findUserByCerticateSerialNumber($openSSL_Bob->getCertificateSerialNumber()); $database->insertMessage($FromUser_id, "3", $encrypted_message, $encrypted_AES_key); echo "<h4>notifica o Bob </h4>"; echo "IMPECAVEL"; // FIM PRIMEIRA PARTE // SEGUNDA PARTE //recebe a notificacao echo " <h1> <br>PARTE 3 </h1>"; echo "<h4>recebe a notificacao </h4>"; echo "<h4>Tem " . $database->checkForNotifications("3") . " mensagens por ler </h4>";
$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>"; print "<p>CA Distinguished Name:<br /><pre>"; print_r($openSSL->getCA(), 1) . "</pre></p>"; print "<hr />"; // encrypt some text using the public key $text = "The goat is in the red barn."; $encrypted = $openSSL->encrypt($text); print "<h3>Ecncryption</h3>"; print "<p>Plain text was:<br />{$text}</p>"; print "<p>And encrypted text is:<br /><pre>{$encrypted}</pre></p>"; // decrypt it using the private key $decrypted = $openSSL->decrypt($encrypted, $passphrase); print "<p>Decrypted with Private Key:<br />{$decrypted}</p>"; // sign some message using the private key $message = "So long, and thanks for all the fish."; $signed = $openSSL->sign($message, $passphrase); print "<h3>Signing</h3>"; print "<p>Signed using Private Key:<br /><pre>{$signed}</pre></p>"; // verify signature $verified = $openSSL->verify($signed); print "<p>Verifying signature using Certificate:<br />"; if ($verified) {