예제 #1
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$password = "******";
$plaintext = "Here is my test vector. It's not too long, but more than a block and needs padding.";
$cryptor = new \RNCryptor\Encryptor();
$base64Encrypted = $cryptor->encrypt($plaintext, $password);
echo "Plaintext:\n{$plaintext}\n\n";
echo "Base64 Encrypted:\n{$base64Encrypted}\n\n";
예제 #2
0
<?php

$userKey = $_POST["key"];
$config = array("digest_alg" => "sha512", "private_key_bits" => 2048, "private_key_type" => OPENSSL_KEYTYPE_RSA);
// Create the keypair
$res = openssl_pkey_new($config);
// Get private key
openssl_pkey_export($res, $privKey);
//Load Encryptor and encrypt private key to server hard drive
require __DIR__ . '/autoload.php';
$aes = new \RNCryptor\Encryptor();
$EncryptedData = $aes->encrypt($privKey, substr($userKey, 0, 256));
file_put_contents(substr($userKey, -10) . ".txt", $EncryptedData);
//Delete the private key and user key from memory
unset($privKey);
unset($userKey);
// Get public key
$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey["key"];
function getStatusCodeMessage($status)
{
    $codes = parse_ini_file("codes.ini");
    return isset($codes[$status]) ? $codes[$status] : '';
}
function sendResponse($status, $body = '', $content_type = 'text/html')
{
    $status_header = 'HTTP/1.1 ' . $status . ' ' . getStatusCodeMessage($status);
    header($status_header);
    header('Content-type: ' . $content_type);
    echo $body;
}