Sunday, November 28, 2010

Asymmetric Encryption and Signing with RSA in Silverlight

While Silverlight is a powerful tool for rich client applications, it lacks the ability to perform asymmetric encryption out of the box.  In this article, I'm going to share a cryptography class library I've been working on and show you how to use it to perform standards compliant RSA Encryption in Silverlight that is cross compatible with .NET's built in RSACryptoServiceProvider, allowing you to encrypt from Silverlight using my library and decrypt on your website using the RSACryptoServiceProvider.  For brevity, only examples using my class library will be shown except for a few examples that show equivelant functionality from the RSACryptoServiceProvider (RSACSP).
Update 11/24/2010: The Scrypt library has been updated.  Key generation is now performed Asynchronously to avoid blocking the UI thread and freezing the browser.  I've updated the applicable source samples in this article to reflect the changes.
Edit*:  I've decided to open up the source for this project. You can download this library and/or source and view the current applicable license on its new home at CodePlex: http://scrypt.codeplex.com/
Background
Before I get into the sample code, I'm going to give you a little bit of background.
What does it all mean?
RSA is an encryption scheme that uses a public and private key.  There are a variety of uses for RSA.  The two most common are encryption to protect data, and signing to verify the authenticity of data.  Encryption is performed with the public key, with the premise that data encrypted with the public key can only be decrypted using the private key.  The private key should be kept safe and secure and the public key can be shared with everyone.  Signing works the opposite direction and is used to verify the source of data.

Read more: Dustin Horne