I get this error when I try to decrypt the string that is encrypted:
I would like to know what the solution is because this should work :-)
{"The data to be decrypted exceeds the maximum for this modulus of 128
bytes."}
code:
// Read public key into a string
public const string PUBLIC_KEY =
"<RSAKeyValue><Modulus>zlOXtyPGngT3Q+bRgMfFxloxmf7 D872ytE+ecqJWzTasBuCG9RlUfKr3IzglP4dByH+QHSkpAoKV9 bM5IJz0/UR88NQp6s10+5w6OkEo/zcQ//Zrqv8AxgtZDx/0cYZmBEqqIJPu9ecZZIxKYGJFCQ4v+b5gPnIDKwe4WA0Seyk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
public static string RSAEncryption(string text, bool DoOAEPPadding)
{
string result = String.Empty;
if (String.IsNullOrEmpty(text))
{
return result;
}
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
try
{
RSA.FromXmlString(PUBLIC_KEY);
result = Convert.ToBase64String(
RSA.Encrypt(
Encoding.Default.GetBytes(text),
DoOAEPPadding
)
);
}
catch (Exception ex)
{
string m = ex.Message;
}
finally
{
RSA = null;
}
return result;
}
public static string RSADecryption(string text, bool DoOAEPPadding)
{
string result = String.Empty;
if (String.IsNullOrEmpty(text))
{
return result;
}
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
try
{
RSA.FromXmlString(PUBLIC_KEY);
result = Encoding.Default.GetString(
RSA.Decrypt(
Encoding.Default.GetBytes(text),
DoOAEPPadding
)
);
}
catch (Exception ex)
{
string m = ex.Message;
}
finally
{
RSA = null;
}
return result;
}