Cottleston Pie

Fernando Felman’s thoughts on software development

Encryption / license issues when upgrading from .Net 1.1 to .Net 2

Posted by Fernando Felman on April 1, 2007

I’ve been called to help in the migration of a .Net 1.1 product to .Net 2. Most of the functionality worked just fine after upgrading but we had an issue with the licensing module: some of licenses we issued failed to validate after the upgrade, throwing a CryptographicException: “Length of the data to decrypt is invalid”. The issue we were having had to do with the changes that the .Net 2 introduced to the GetBytes() method in order to be compliance with the Unicode standard (read full details here):

Encoding.GetBytes() may not emit unpaired high or low surrogate characters for certain encodings (e.g. UTF-8 Encoding and UnicodeEncoding).

The solution was quite simple once the problem was identified: instead of using Unicode.GetBytes to transform the cipher bytes to string we use Convert.ToBase64String (and its symmetric opposite Convert.FromBase64String). The original problem was identified by reading shawnfa’s post from the .Net Security team blog. More details of this problem and how to solve it using the Base64 conversion can be found in the CodeClimber blog.

Tips: If you plan to upgrade a .Net 1.1 application to.Net 2, take a good look into this article. If your application is a web application, also consider reading the articles in this page.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: