C# RSA and PHP

Arsium ***** 331 Reputation points
2021-08-31T19:23:17.433+00:00

Hello,

Currently, I'm trying to play with PHP SQL and C# but I got some problems with private and public keys + encryption and decryption. (I cannot write code in php here idk why : ''You don't have permission to access "http://learn.microsoft.com/answers/questions/ask.html" on this server.'') So I set a pastebin link with php code.

C# :

     string key = ((string)json.rsaPublic).Replace("-----BEGIN PUBLIC KEY-----", "").Replace("-----END PUBLIC KEY-----", "");  
      
                        byte[] toEncrypt = Encoding.UTF8.GetBytes(Utils.tempAESKey);  
      
                        RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();  
      
                        RSAParameters RSAKeyInfo = RSA.ExportParameters(false);  
      
                        RSAKeyInfo.Modulus = Encoding.Default.GetBytes(key);//Public Key  
      
                        RSA.ImportParameters(RSAKeyInfo);  
      
                        string encryptedAESKey = Convert.ToBase64String(RSA.Encrypt(toEncrypt, false));  
      
                        string sendAES = httpRequest.Post("requestWithencryptedAESKey").ToString();  
      
                        MessageBox.Show(sendAES);//Empty  
  

PHP : https://pastebin.com/raw/ZxitjiBj

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
{count} votes