RSACryptoServiceProvider fails if we delete a user from the machine

Hi all, The other day a customer of mine had an interesting issue: a specific user runs their application for the first time without problem on a machine. Any other user can run the app without problems on the same machine, too. If that specific user is deleted from the machine, any other user will…


CryptSignHash fails with NTE_BAD_KEYSET

Hi all, The other day I worked on the following issue: a customer of mine had developed an ActiveX which they used to sign some data in Internet Explorer. Their signing code was based on CryptoAPI and worked just fine with some certs, but failed with others with a NTE_BAD_KEYSET error. So we took some traces with…


How to sign EXE files with an Authenticode certificate (part 2)

Hi all, welcome back, The other day a customer of mine was having an issue with SignTool.exe when signing an EXE file. The EXE file was getting corrupted/unusable after signing it. When troubleshooting this issue, I had the chance to play a bit more with SignTool and check what it does behind the scenes. Note: I…


How to change Windows Theme programmatically in XP

Hi all, You may know already that there is no i.e. COM object or .NET class we can use to change the Windows Theme programmatically on Windows XP. You may also know the following VBScript which can be used to do this change without user intervention:Set OSHApp = CreateObject(“Shell.Application“) Set oShell = CreateObject(“Wscript.Shell”) ‘ Set…


How to clean up expired certs on your smart card

Hi all, The other day a colleague of mine was trying to renew his smart card certificate, but he got an error telling him that there was not enough space in the card to store the new cert. So he asked me: Alex, how can I delete a certificate from my smart card so there is…


RSACryptoServiceProvider.Encrypt returns "Key not valid for use in specified state" error

Hi all, When executing RSACryptoServiceProvider.Encrypt method (see How to generate key pairs, encrypt and decrypt data with .NET (C#) for an example), you may get a System.Security.Cryptography.CryptographicException. According to MSDN, this is to be expected in several circumstances: The cryptographic service provider (CSP) cannot be acquired. -or- The length of the rgb parameter is greater…


How to generate key pairs, encrypt and decrypt data with .NET (C#)

Hi all, The other day a colleague of mine asked me if I had a .NET version of the C++ sample in How to generate key pairs, encrypt and decrypt data with CryptoAPI post. C++ sample calls CryptoAPI directly (and you know we can do the same thing in .NET through P/Invoke), but the idea was to use…


Something has changed in my life

Hi all, Sorry I haven’t been able to write anything for a few weeks. I’ve been on vacation + paternity leave… Paternity leave! Yes, I’m a father now! My son Nicolas was born on Sept 11th, 2008, and he’s taken pretty much all my free time since. WELCOME TO OUR WORLD NICOLAS!!! I’ll try to…


The use of MSXML is not supported in .NET applications

Hi all, The other day I was working with a customer of mine on a .NET application which was suffering from a memory leak. The weird thing was that the application could run just fine for 10 days in a row before the memory began growing and growing. What was going on? Why was the Garbage…