- Create your public key and private key
// Config RSA
$config = [
"digest_alg" => "sha512",
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
];
// Create the private and public key
$res = openssl_pkey_new($config);
// Extract the private key from $res to $privateKey
openssl_pkey_export($res, $privateKey);
// Extract the public key from $res to $pubKey
$pubKey = openssl_pkey_get_details($res);
$publicKey = $pubKey['key'];
openssl_public_encrypt($data, $encrypted, $rsa->publicKey);
openssl_private_decrypt($encrypted, $decrypted, $rsa->privateKey);
- Put data encrypted through URL:
$url = urlencode(base64_encode($encrypted));