I want to make an application, in Xamarin, with a connexion. So, I want to encrypt my password to not be vulnerable on the network, and then encode it in base 64. I made it in Symfony to decrypt my password :
/**
* @Route("/Decrypt", name="Decryption")
* @Method({"POST"})
*/
public function Decryption(Request $request){
$passwordEncrypted = $request->headers->get("x-password");
$rsa = new Crypt_RSA();
$passwordEncrypted = base64_decode($passwordEncrypted);
$pr_key = file_get_contents("private.key");
$rsa->loadKey($pr_key);
$password = $rsa->decrypt($passwordEncrypted);
$data = $this->get('jms_serializer')->serialize($passwordEncrypted, 'json');
$response = new Response($data);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
But I don't know how to encrypt the password in my Xamarin side. I found few samples on Internet but no explanation with them. For the moment, I have :
public partial class ConnexionPage : ContentPage
{
private void Connexion(object sender, EventArgs e)
{
byte[] publicKey = Encoding.ASCII.GetBytes("/*I insert my public key*/");
byte[] testData = Encoding.UTF8.GetBytes("test");
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RSAKeyInfo = RSA.ExportParameters(false);
RSAKeyInfo.Modulus = publicKey;
RSA.ImportParameters(RSAKeyInfo);
byte[] encryptedData = RSA.Encrypt(testData, false);
}
}
I just do a test for the moment but I get a result : A byte Array with a size of 280. But when I convert it in base64 and test it into my Symfony side, i don't fall back on "test".
Can someone help me please?