I have a C# server that will generate a RSA KeyValue Pair. The public key will be sent to a PHP client which will then encrypt some data and send to server. The server will then decrypt using the private key it has.
I am doing that using the following code in C# -
CspParameters cspParams = new CspParameters { ProviderType = 1 };
RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(1024, cspParams);
string publicKey = Convert.ToBase64String(rsaProvider.ExportCspBlob(false));
string privateKey = Convert.ToBase64String(rsaProvider.ExportCspBlob(true));
Now I need to pass on the public key generated to a PHP Client. But the problem is that Key String generated here in C# is not recognised by PHP when i use it in the function as below -
public function encrypt($data)
{
$pubkey = 'BgIAAACkAABSU0ExAAIAAAEAAQBdZ3klDbVjH8oiBtGzHIMixo/TKPlv492kuau9chnARvkpxaRd8Qa82kIF2AvrEllhzjD07UHkVxoVZA2aYN+t'
$pubKey4 = openssl_get_publickey( $pubkey );
openssl_public_encrypt($data, $encrypted, $pubKey4 )
}
openssl_public_encrypt()
function shows such warning:
Warning: openssl_public_encrypt(): key parameter is not a valid public key in C:\wamp\www\rsa\index.php
Please suggest, what shall be the format of the public Key that shall be recognised by PHP.
X509 certificates are not an option.