RSA RSACryptoServiceProvider in the .NET Compact Framework using the public key from the full .NET Framework

In my work, we do encryption to protect data and the data is encrypted by the .NET Compact Framework and must be read by the regular .NET platform on the server. We encounter a problem when a compact structure cannot encrypt (throw exception) using RSA with a well-known public key. The server transfers the public key to a compact wireframe device. The following is a test application written for a compact structure to show the problem.

string mod = 
    "rgTcL0/ZK3j5Rt6CigEsfyLDiERh2PuVzmZVdHbb/2jQOG5JEcAqqBoscDZ4PwJR8aO19xNVTce7"
  + "vzbEued32z2PLAvCcHFKGtOgNEeZ+ZcD6uHobsKws76BdjBrI7Pigk2HSkak21n2WoVcBVHoRmcn"
  + "eX7DPaB4atamhkbLoRBF1VlautDfhX9lnOFA2zyZUCB5CproavKF6wl19pZne2Q4U1vMtBAA2Q9N"
  + "aZFsrj/KjE3UtYKvjd4Oy55Hmtpb5P3CZAVpiyCTKq3gTxDJn69giyctu428DgkKacmZ4yTvkLWB"
  + "Ym/zWtAf9o8pI+3MwgF7wzuK5ypGack3l4/Skw==";

string exp = "AQAB";

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048);

RSAParameters p = new RSAParameters();
p.Modulus = Convert.FromBase64String(mod);
p.Exponent = Convert.FromBase64String(exp);

rsa.ImportParameters(p);

var bytes = rsa.Encrypt(System.Text.Encoding.ASCII.GetBytes("MIKE"), true);

This code throws the following exception when the Encrypt method is called:

Framework: 3.5.7283.0
Exception: fOAEP 
InnerException: Could not evaluate expression

Stack Trace:
   at System.Security.Cryptography.RSACryptoServiceProvider.Encrypt
    (Byte[] rgb, Boolean fOAEP)

- - , /? .NET, . , . .

!

+3
1

All Articles