<?php
include('Crypt/RSA.php');

$rsa = new Crypt_RSA();

//$rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
//$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);

//define('CRYPT_RSA_EXPONENT', 65537);
//define('CRYPT_RSA_SMALLEST_PRIME', 64); // makes it so multi-prime RSA is used
// extract($rsa->createKey()); // == $rsa->createKey(1024) where 1024 is the key size

/*
    $rsa = new Crypt_RSA();
    // extract($rsa->createKey());
    $key = $rsa->createKey();
    extract($key);
    print_r($key);
*/


$privatekey = <<<EOT
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCZtAsXevilwj+XrZvnr9UTz1bqiFHnYvt0DSXrlaNaaYxfKzXN
prHBn9bLxe40wsFElQ2njNhnzEhgn0r1AhyItHatfEjaSZ+10YqA1EQ3wytCX7Kg
UPGCrBKVjdSayawhrExqfKOJUYlJhDBhCV0fR2hRWR6bSiKIUK8UnMvyzwIDAQAB
AoGABvYXKBzjFN02wU+umpBL7gkoKzHs+ILZV284Nj9674Xz3DEtaNjRsi6wE5It
ik9lYdrL8uu3g82S9Zu66sMJ61Q44oluEkNtgtWd5R12BSbmEIhOoVZYJZVbNAuh
zPBgGeCaaFXyhsroBnRjzsRKnDW9KJKwsAFJwqU3GSkqHBkCQQCwuep6o3Xz5/+P
d1UmMrrbVx6MFzxwc5I9wLTh3Jrp22qoVNmonadwSDGNeNhgliVEqNY+1AhJ0MOR
/2bc9+prAkEA3qZS24G2PoTsjG0mY13DnkrmcCHdDpNM4SI7/NSbI6MNB6JFrQ0L
yxq3gM+nAodIXMahOEzcNdSTyvkGlDK6LQJBAJEk0GhS0fA1TVZF+t/5cC/u+D60
YsY0lRo0qBqMNYr10z5XGcB7YuY71L7NTmDdT9R5GiTVvczqMYU6DwBSeOsCQELx
rW4UlTA9FUavtuAfnCanDJxggi/UuEPk4DaH0lGnv84wy1RZ3NbnpI8VYHjRJj/G
9UiRS5Df5sQblg/PJM0CQAOyGrB9nmGMS+dCosmPTFWiX9Ne4D/4+zd5St9uDeN2
70sk+uPQzJEPHOP4F83EHBCJxTmzJGRXqi9YkVe/9E4=
-----END RSA PRIVATE KEY-----
EOT;


$publickey = <<<EOT
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZtAsXevilwj+XrZvnr9UTz1bq
iFHnYvt0DSXrlaNaaYxfKzXNprHBn9bLxe40wsFElQ2njNhnzEhgn0r1AhyItHat
fEjaSZ+10YqA1EQ3wytCX7KgUPGCrBKVjdSayawhrExqfKOJUYlJhDBhCV0fR2hR
WR6bSiKIUK8UnMvyzwIDAQAB
-----END PUBLIC KEY-----
EOT;


$publickey2 = <<<EOT
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXj0oWWs6byiJfup9u9c3zpQTv
k3YB5iVqL2C2n3j8w3Dl1bKNk8qK5KEj6wRImfhnYuNPtKT2wmQf871fVneNdeSE
6VS86fVoJrcfVeWA6uilTQB30zLGkYkJkBXombotkqyfSEIfNa+3Z7mbvY+RpMMp
xBV7dqe4fCqZCI8kiQIDAQAB
-----END PUBLIC KEY-----
EOT;


$publickey2 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXj0oWWs6byiJfup9u9c3zpQTvk3YB5iVqL2C2n3j8w3Dl1bKNk8qK5KEj6wRImfhnYuNPtKT2wmQf871fVneNdeSE6VS86fVoJrcfVeWA6uilTQB30zLGkYkJkBXombotkqyfSEIfNa+3Z7mbvY+RpMMpxBV7dqe4fCqZCI8kiQIDAQAB";



$privatekey2 = <<<EOT
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCXj0oWWs6byiJfup9u9c3zpQTvk3YB5iVqL2C2n3j8w3Dl1bKN
k8qK5KEj6wRImfhnYuNPtKT2wmQf871fVneNdeSE6VS86fVoJrcfVeWA6uilTQB3
0zLGkYkJkBXombotkqyfSEIfNa+3Z7mbvY+RpMMpxBV7dqe4fCqZCI8kiQIDAQAB
AoGAAqJ1x/4znb8tikr49wmUVzIs7Ao88KsCxv4EWSBcDs7J8WDd3fqt+GyhhXmS
JT3x9MAiEfJitLxr16dZySS8ZsTproARLy4H7IK3ZC2/AeFZfR/cWgIyXv8QlRkp
yf/1Qc6Uic40i6jTJqY1ZMAoySI/y8wckiS+Ner6aGcQRbUCQQCkHJKoyMxRS5IF
u6TAG/flqorUoDtUzk9y+lxXGwSgRpiZCfoyJUepFktG+1zb6dtMJzOOPUkae5Xu
fiNkGkLdAkEA7GuN3RJCreAJx8t4iCaJVWGAPbtxAjYhvohZIEmO7DEtTvJ/nhhg
0cvRumDjW1G3r8GIr3EcNjq0datAHKL/nQJBAIFBx/mMffCh1tcRHgf5f1yy4Dns
Ig7/l+/1ZPluXExojhQrmZYZasGwv4WewVqsbH8keSTU/FkRcduwGevkCzkCQGlx
CqNXWo/LxPDryYUHkuaWhqiBqcQvulsM2psw02J6CFgWhV5QRxYqjg5O2ffHeWIU
sc51Zvy0r/lu+DgNZm0CQAILv20LC89aPcKUj+fjVFrK8VPCkKMXH3WEGI3Se18I
xrvYrRXM5BiN2TOPEEp3WRE+i2m4lyvpBpNSFcchLMA=
-----END RSA PRIVATE KEY-----
EOT;


    echo "<hr />";
    echo "privatekey:<br />";
    echo $privatekey;
    echo "<hr />";
    echo "publickey:<br />";
    echo $publickey;
    echo "<hr />";


    echo "privatekey2:<br />";
    echo $privatekey2;
    echo "<hr />";
    echo "publickey2:<br />";
    echo $publickey2;
    echo "<hr />";


    $plaintext = 'terrafrost xyz monkey in a tree!';


    $rsa = new Crypt_RSA();
    $rsa->loadKey($publickey2);
    //$rsa->setPublicKey($publickey2);
    $ciphertext = $rsa->encrypt($plaintext);
    echo "<br /><hr /><br />";
    echo "ciphertext (raw):<br />";
    echo $ciphertext;


    $ciphertext = base64_encode($ciphertext);

    echo "<br /><hr /><br />";
    echo "ciphertext (base64):<br />";
    echo $ciphertext;

    echo "<br /><hr /><br />";

    $rsa = new Crypt_RSA();
    $rsa->loadKey($privatekey2);

    $ciphertext = base64_decode($ciphertext);

    echo "decrypt:<br />";
    echo $rsa->decrypt($ciphertext);

?>
