.Net 1.1 RSA Cryptography code throws exception in .Net 2

I wanted to use the RSA cryptography classes and had some C# code from .Net 1.1  I wanted to encrypt with the private key and decrypt with the public key.  However, the .Net 1.1 code that works OK throws an exception if run in .Net 2 when trying to decrypt using the public key.  I have tried different  CspParameters flags but to no avail.  ANyone found the solution?

CspParameters cspParams = new CspParameters();

cspParams.Flags = CspProviderFlags.UseMachineKeyStore;

RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

string publicKey = RSA.ToXmlString(false);

string privateKey = RSA.ToXmlString(true);

String str = "Some Text to Encrypt / Decrypt";

RSACryptoServiceProvider RSAencrypt = new RSACryptoServiceProvider(cspParams);


byte[] encryptedBytes = RSAencrypt.Encrypt(System.Text.Encoding.Unicode.GetBytes(str), false);

string encryptedString = System.Text.Encoding.Unicode.GetString(encryptedBytes);

RSACryptoServiceProvider RSAdecrypt = new RSACryptoServiceProvider(cspParams);


byte[] decryptedBytes = RSAdecrypt.Decrypt(System.Text.Encoding.Unicode.GetBytes(encryptedString), false);

string decryptedString = System.Text.Encoding.Unicode.GetString(decryptedBytes);

If it was easy, everybody would be doing it.
9/15/2005 12:15:12 PM
asp.net.migrating-from-1.x-2.0 1016 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 52

Around the forums it looks like this is an issue for a number of people.  Having fiddled on a bit further, maybe it isn't possible to use the class to perform public key decryption in .Net 2.0 (and might be intended by Microsoft).

For my solution, I've figured that digital signing will be sufficient because if the intended decryption key is public anyway, the contents aren't necessarily safe.

To use RSACryptoServiceProvider for signing (assures the recipient of your data that you alone can only have provided the data), proceed as follows,

Create a new RSACryptoServiceProvider instance.  This contains the private/public key pair by default.

Create a digital signature using RSACryptoServiceProvider.SignDate

Send the signature, the data, and the public key to the recipient (you'll want to package up some sort of XML or base64 strings, or both)

At the recipient, create a new RSACryptoServiceProvider instance.  Overwrite the default private/public with the public key provided

Verify the data against the signature

You can tamper with data sent to the recipient to verify signature failure, and even attempt to sign the data using the public key only - which will fail (as expected!)

Some code is provided below as an example.

public static void SignData()


// construction generates private/public keypair by default.

// You'll need to store the keys in a database/file etc. for later proof of posting,

// or you can re-use the same keypairs again by storing the key string for loading again using rsaSinging.FromXmlString(keys);

// i.e. string keysToStore = rsaSinging.ToXmlString(true);

RSACryptoServiceProvider rsaSinging = new RSACryptoServiceProvider();

// I'll pull out the public key here for inspection

string publicKey = rsaSinging.ToXmlString(false);

// convert using unicode since that is what a string is (don't rely on ASCII [7-bit] encoding)

String stringToSign = "Some Text to Sign";

byte[] data = Encoding.Unicode.GetBytes(stringToSign);

// perform the signature

byte[] signature = rsaSinging.SignData(data, "SHA1");

// now verify this using an independant rsa class instance

VerifySignature(publicKey, data, signature);


public static void VerifySignature(string publicKey, byte[] data, byte[] signature)


RSACryptoServiceProvider rsaSignatureCheck = new RSACryptoServiceProvider();

// load the public key


// check signature of data

bool signatureValid = rsaSignatureCheck.VerifyData(data, "SHA1", signature);


If it was easy, everybody would be doing it.
9/16/2005 1:47:22 PM

Similar Artilces:

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0 #2
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! There are too many differences for one email - - from 1.0 to 1.1 (not a whole lot of real change, other than fixes, at least compared to 1.1 to 2.0) With 2.0, there were many new declarative controls, with many new ideas added in With 3.0, it's a superset of 2.0 - instead of replacing the installation completely, it just 'added on' new functionality - I would...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! Have a look into this links http://en.wikipedia.org/wiki/.NET_Framework http://blogs.msdn.com/mohammadakif/archive/2006/12/03/net-3-0-different-versions-of-the-net-framework.aspx http://www.codeproject.com/aspnet/ComparisonASP1xASP20.aspAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that m...

Migration from .NET 1.1 to .NET 2.0
Hi All, Well i hoped that the migrating went smoother then is does so far. I had a few problem which i could fix with blogs from other developers, but i didn't find a good solution for this problem. Somehow i get the following error: "Make sure that the class defined in this code file matches the 'Inherits' attribute, and that it extends the correct base class" Well i worked very good before the migration. Some advise would be very welcome! Regards,Dennis van de Laarhttp://dennisv.net/Don't forget to mark the most helpful reply/replies as Answer. Maybe this post will hel...

Code works with .Net 1.1 but not .Net 2.0
Can anyone offer any suggestions as to why this code would work under .Net 1.1 and not .Net 2.0? I listed the error I receive below, also. Line 865. Thank you, Public Function GetAge(ByVal Birthdate As System.DateTime, _ Optional ByVal AsOf As System.DateTime = #1/1/1700#) _ As Integer Dim iMonths As Integer Dim iYears As Integer Dim dYears As Decimal Dim lDayOfBirth As Long Dim lAsOf As Long Dim iBirthMonth As Integer Dim iAsOFMonth As Integer If AsOf = "#1/1/1700#" ...

Migrate DataGrid .NEt 1.1 to .NEt 2.0
Hi I has just convert my ASP.NET web application from .NET 1.1 to .NEt 2.0 so far there is no problem but my datagrid seems to be acting really weird my datagrid has 3 columns and have paging enabled. When there is one/two row of data. The paging(which shows us the number of page) seems to have a column span of 1)  If i click on the second row of data.... the paging will have the column span of 3 This does not happen if there is more than 2 data   please go to the link for better clarification http://yingleekit.multiply.com/photos/album/1/work#1 http://ying...

Where is the ADO.NET Sybase driver for .NET 1.1 and .Net 2.0?
Hi All Does anyone know where I can get the Sybase drivers for ADO.NET for both versions, 1.1 and 2.0/3.0? Cheers Chris Burrell Hi Chris, There is no release of ASE ADO.NET Provider 2.0 (I assume you refer to ASE provider, not ASA - if ASA please port to sybase.public.sqlanywhere.general). For the 1.1 Provider: It is available in the ASE SDK for windows or the PC Client CDRom included with ASE product. On the SDK its available as 12.5.1 and 15.0 On ASE PC Client I think 12.5.1 is part of ASE 12.5.X and 15.0 is part of ASE 15.X 2.0 provider should release som...

.net 2.0 to .net 1.1
Hello , This is shrirang. Currently i am working .net2.0 web application. but the same application is runing on production in .net 1.1 freamwork . we are not using any new feature of 2.0 in our application . can i run build of 2.0 on 1.1 freamwork . if yes can you  please tell me necessary steps to achive it .     Thanks in advance for your kind help     Regards Shrirang i think it is not possible to run the 2.0 application in 1.1 , so try to change to the frame work in the production server . ThanksRaja Ragothaman Hi Shrirang, Please contact web adm...

having .net 1.1 and .net 2.0
Was just wondering if you someone could tell me the ramifications of the following:  I have .net 2.0 but did not uninstally .net 1.1, i have visual studio 2003, and visual web developer installed on the computer as well as sql server 2000.  my question is whether that is a problem having the two runtimes installed at the same time?  i did this because i wanted to use VWD but keep vs 2003 in case i needed to do any development for work....any comments are appreciated.  --jpIf my post is helpful please mark as answerRegards -- jp(http://www.rzrsolutions.com/rzrWeb20/...

Migrating .NET 1.1 to .NET 2.0/3.5
We have many of our application running in .NET 1.1, and plannig to migrate all one-by-one, i know there will be a big challenge for this activity, What we are planning is not to migrate all in one shot, After migrating one application we will give for some selective users testing once we feel it is OK, do the next. What is best way of doing this thing? Any links, thrid party tools, since opening this in VWD 2005, it is converting the application but many errors are popuping up. Any reference would be highly appreciated, thanks in advance. Hi, Please follow the steps mentioned in this l...

Problem with Project Migrating from .net 1.1 to .net 2.0
Hi i am working in .net 1.1 and i am working on a web service. it 's working fine in .net 1.1 with vs2003 but when i migrated my WS from .net 1.1 to .net 2.0 i am getting System.FormatException while converting datetime from string using DateTime.Parse method. it was not happening earlier when i was using .net 1.1. My WS converted from vs2003 to vs2005 using a wizard and it doesn's shows a single error.   i did lots of googling on this issue but didnot gets any help , so any reply in the matter will be highly appericiable.  thanks vishal sharma vishalsharma808...

Conversion of code from .net 1.1 to .net 2.0 posing a problem
Originally Posted by Akshay_Jadhav on the Microsoft Interoperability - Technical Interoperability Scenarios forumHI,I have converted .net 1.1 code to .net 2.0 using .net wizard. i have radiobutton whose checked property is set to false on page load, on clicking of a button on that page checked property of radiobutton is set to true and a dropdownlist is enabled. when i select some value in dropdownlist the page is posted back and checked property of radiobutton is again set to false(automatically) which is wrong, it should be true. Same code is working fine in .net 1.1,when i select som...

What are the advantages of migrating applications written in .NET 1.1 to .NET 2.0?
Hello,Can someone tell me the advantages of migrating my current aplication which has been developed in ASP.NET 1.1 to ASP.NET 2.0? I have read and implemented some of the technical advantages that come with ASP.NET 2.0 and .NET 2.0. But how do I convince our customer that we should upgrade the existing application in production for a couple of years now to .NET 2.0... like the performance benefits we gain by doing that? Read that .NET 2.0 is a lot (around 40%) faster than .NET 1.1 and has all those performance enhancing features like the precompilation, enhanced data caching... in addition ...

Unable to debug .net 1.1 applications after installing .net framework 2.0 ? #2
Hi, After you install .NET Framework 2.0, if you continue to use Visual Studio.NET 2003 you may be unable to debug the applications developed in .NET 1.1. You may receive the error "Unable to start debugging on the webserver..." Please check My Article on this issue and the resolution for the same. Comments are welcome. Thanks. regards,Harishhttp://geekswithblogs.net/ranganh...

Any advantages of migrating to .NET 2.0 on still using .NET 1.1 projects?
Sorry for the noob Q - but will I get any advantages in installing .NET 2.0 Framework alongside .NET 1.1 if I dont plan to upgrade my ASP .NET 1.1 web applications?I have a few servers that I will be installing the .NET 2.0 Framework so as to develop in VS2005, however on some servers that will not (at this stage) be used for .NET 2.0 apps and that I may not have the time to convert some VS2003 applications to VS2005, I was in the 'if it aint broke, dont fix it' kind of thinking and didn't know if installing .NET 2.0 would bring any advantages.TIA.  I happen to agree. If you don't nee...

Web resources about - .Net 1.1 RSA Cryptography code throws exception in .Net 2 - asp.net.migrating-from-1.x-2.0

Public-key cryptography - Wikipedia, the free encyclopedia
In an asymmetric key encryption scheme, anyone can encrypt messages using the public key, but only the holder of the paired private key can decrypt. ...

So much of what interests me and consumes the tech industry these days relates to Cryptography, and in particularly public key cryptography. ...

New business collaboration platform secures data with personalized cryptography
Data security is a big concern for both individuals and businesses. This doesn't only apply to the public face of a business, but to exchange ...

Your Smartphone's Camera Holds The Secret For Unbreakable Quantum Cryptography
Mathematicians concerned with cryptography need novel ways of generating random numbers in order to securely transmit data such as a credit card ...

Cryptography expert casts doubt on Telegram's encryption algorithms
Jihadists continue to try to use the app despite its creators banning ISIS-related channels.

Digital privacy: Cryptography for dummies
A CAMPAIGN by American and British lawmakers and security officials to get social-media companies to take more responsibility for handing over ...

Witkit Collaboration Platform Features Personalized Cryptography
Features like secure and encrypted storage, messenger and video conferencing services round out the array of services available at launch.

Is the NSA trying to warn us that cryptography is dead?
NSA has updated its advisories for worldwide cryptography practices, and may have revealed its thinking on the real future of crypto.

Security Company's Cryptography Play Aims At Tech Firms, Finance
A new suite of tools by startup Dyadic can stop a cybersecurity breach in progress. Almost all companies use cryptography—the creation of secure ...

Surveillance Complex Urged To 'Stop Blaming Cryptography For Paris Attacks'
Security experts are concerned about the exploitation of a tragedy to increase surveillance and the focus on technology rather than failures ...

Resources last updated: 12/17/2015 6:51:13 PM