<?php
echo "start: " . date("Y-m-d h:i:s") . "\n";
$str = "test";
// this is known as your certificate or "public" key
$cert = file_get_contents("/path/to/hostname.cert");
// this is known as your "private" key
$key = file_get_contents("/path/to/hostname.key");
echo "cert: \n$cert\n";
echo "key: \n$key\n";
if( !openssl_public_encrypt($str, $enc, $cert) )
exit('encryption failed');
if( !openssl_private_decrypt($enc, $dec, $key) )
exit('decryption failed');
$bEnc = base64_encode($enc);
echo "plain: $str\n";
echo "encrypted: $enc\n";
echo "encrypted (base64): $bEnc\n";
echo "decrypted: $dec\n";
echo "end: " . date("Y-m-d h:i:s") . "\n";