Пример #1
0
?>

<?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>";
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>";