I have a encryption C# code, that i'm trying to implement in PHP and phpseclib and get exactly same results. It's RSA. But I cannot get it done. It gives me empty string in PHP as encoded.
Public key is in this format:
<?xml version="1.0" encoding="utf-16"?>
<RSAParameters xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Exponent>AQAB</Exponent>
<Modulus>sMFsHSyxAP5N85yvx/XDs9acJa30qwBjoOdDKvNOHJUYBpspwatkdtErCqM2W6tXH9rbvhIn8/nqW4OqAdLinlgkEJoQ/qnzKjYJhHl4YzKFL6Wp+iFRH6ar6ZWOE87LeNQ0nHwlXKoWkJQKV8NB38XRw6aLvNTj8Po2yaFDbQFztsJ+ILkumRh7Leu77IV+124Swc6JqLRt5z2FnDX869dRi2fqcnFa1EHEBsPEndVd2HSeJUncTQiWJ9SNRU+WLltVVewYiGheqr1ABab++3XM5qrB6fWn/RN9Fcg5nM8fachAFSX2YRrEsg7mcbNALRes6OEdpI0LBdX8Wdw6oQ==</Modulus>
</RSAParameters>
The C# code is:
public static string Encrypt(string data, string public)
{
RSAParameters pubKey = public;
var csp = new RSACryptoServiceProvider();
csp.ImportParameters(pubKey);
var bytesPlainTextData = System.Text.Encoding.Unicode.GetBytes(data);
var bytesCypherText = csp.Encrypt(bytesPlainTextData, false);
return Convert.ToBase64String(bytesCypherText);
}
In PHP i'm doing this, but results an empty string:
$rsa = new Crypt_RSA();
$modulus = new Math_BigInteger(($modulus), 16);
$exponent = new Math_BigInteger(($exponent), 16);
$rsa->loadKey(array('n' => $modulus, 'e' => $exponent));
$rsa->setPublicKey(array('n' => $modulus, 'e' => $exponent));
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$encryptedPassword = $rsa->encrypt($password);
echo $encryptedPassword;