473,396 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

RSA problem I can't seem to decrypt

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;
}
May 22 '06 #1
1 15793
Using RSA, you can only encrypt/decrypt a data block which is less then the
key size. That is why typically only Session keys are encrypted with RSA,
then an algo like AES is used for the actual data encryption (and it is
faster.)

--
William Stacey [MVP]

"smilly" <sm****@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
|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;
| }
May 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jimski | last post by:
Hello all, I am having a problem where I get an error message when I call FlushFinalBlock when decrypting my encrypted text. I am using the Rijndael algorithm. The error message is "Length...
6
by: Carolyn Vo | last post by:
Hi there! I have a string that was encrypted in Java using the classes DESKeySpec, SecretKeyFactory, SecretKey, and Cipher. It looks like using the SecretKeyFactory puts a transparent layer on...
7
by: Dica | last post by:
i've used the sample code from msdn to create an encyption/decryption assembly as found here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT10.asp i'm...
0
by: dba123 | last post by:
am getting the following error when a sub domain is receiving a shared cookie: I have this in both web.config of each application. The 1.1 application does not have the decryption= value...
12
by: =?Utf-8?B?am9uaWdy?= | last post by:
I wrote a simple VB.NET application that imports and edits CSV files. Now I’d like to “lock” the raw (pre-import) CSV files so these cannot be opened separately. It is not high-sensitive...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
1
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
2
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
4
by: Protoman | last post by:
Can you please help me figure out what the error is here, in this rotor cipher simulator, which I wrote to amuse myself? The runtime error is that it isn't symmetrical --decrypting a piece of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.