Signing of XML documents make up the foundation for SAML security by providing proof that a message hasn’t been tampered with by a third party. If you’ve ever worked with certificates and signing XML in .NET 2+ you know that it’s not a big deal. The X509Certificate2 class make loading public and private keys from certificates on disk or certificate store a breeze. While you’re probably looking forward to .NET 4 just as much as I am, sometimes your customers have old platforms that just can’t be upgraded to .NET 2.0+ by recompiling it. So if you’re stuck with .NET 1.1 you will run into problems handling certificates. The solution for .NET 1.1, and other languages as well of course,  is a library from Microsoft called CAPICOM. While CAPICOM isn’t a .NET library it’s easily made available in .NET using Interop.

Download CAPICOM SDK from Microsoft

Build the interop-dll by starting up “Visual Studio 2003 Command Prompt” and run the following command in the same directory as the CAPICOM dll:
tlbimp capicom.dll /out:Interop.CAPICOM_NET1.dll
The interop dll is included in my example below

CAPICOM isn’t exactly the X509Certificate2 class for .NET 1, there’s a bit of work to get your signing and verifying on the road. I’ve built a help class which will load your certificates and provide the RSA-class you need to use SignXml, it’s available, as usual, at the end of this post. The demo project containing my helper class is built using VS 2008 but the helper class itself compiles in .NET 1.1. In the CapicomLibrary project folder there’s a bat file that compiles the library into .NET1.1 code (given that you have .NET 1.1 framework installed of course). The reason I’ve chosen to use .NET 2 for my demo project is so that I can use X509Certificate2 to verify/visualize that my code is actually working as intended. Certificates are also included in the demo for testing purposes. Find out more about creating certs using Makecert.exe here.

I hope this post will save you the time wasted (more or less) searching for a valid and compatible solution to sign and verify XML using .NET 1.1.

The Code (show code)

Using the class (showcode)
(remember that there’s .NET 2.0 code here also)

Download my XML signing/verifying example using CAPICOM

Related posts