Reposting from http://www.mentalis.org/forum/thread.qpx/971 because I need an answer. I hope you guys can help me out.

The component in question is Org.Mentalis.SecurityServices.dll.

Hey all. I'm having troubles.

CryptographicException: Couldn't acquire crypto service provider context.

StackTrace: at Org.Mentalis.SecurityServices.Cryptography.CryptoHandle.CreateInternalHandle(IntPtr handle, String container) at ORG.Mentalis.SecurityServices.Cryptography.CryptoHandle.get_Handle() at Org.Mentalis.SecurityServices.Cryptography.RC4CryptoServiceProvider.ctor() at

I had to copy that exception trace by hand, from a screenshot sent to me by a client.

Essentially, I have created a .NET 3.5 WinForms application for XP that uses the RC4CryptoServiceProvider to load encrypted user details from an .ini file on startup. It's worked fine for months.

About a week ago, I got this exact exception message on my computer. I did some hunting online, but couldn't find much - everything I found was related to websites.

I eventually stumbled on a workaround that got things working on my computer. When I deleted the files from the following three folders:

C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys\

C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\token\

C:\Documents and Settings\my_username\Application Data\Microsoft\Crypto\RSA\token\

The problem went away. The folders re-populated with new information the next time I ran the application.

I had thought this was just something unique to my own development environment - that I had downloaded something weird that corrupted my cryptographic files and folders. It's not a field in which I am an expert - I just use the component, and it Just Works. Well... Up until now.

The problem is, one of my company's clients has just recently started experiencing the same error, and I'm not comfortable asking them to just clear out their Crypto files without being able to justify why. Also, it would seem that this wasn't due to something odd that I downloaded, as this exception is arising on a series of commercial Terminal Servers.

I've been looking around for support on this issue, but I'm not having much luck. I'll keep looking around. Can anyone out there shed some light on the situation?

Thanks for your time.

Why don't you use built in .NET encryption routines instead of Org.Mentalis.SecurityServices? Unless there is a specific reason then you could change it over to Microsoft's...

I have a sample login form code snippet posted at:
http://www.daniweb.com/code/snippet217409.html

The method contains encrypt and decrypt routines that I have deployed to hundreds of clients without issue so I would feel comfortable that would fix your issue.

I can't - I have to use RC4 because my application is a front-end to a legacy system that uses RC4 encryption for its passwords, and .NET doesn't support RC4 because there are far more secure encryption methods now.

Unfortunately, although the legacy system for which I'm developing the front-end is owned by my company, it has been decided that the RC4 is still secure enough to not warrant the cost of redeveloping that legacy code.

Hmm, sounds like it has something to do with file / folder permissions.

I thought so too - but the first thing I tried was to give Everyone full access to the files in question to check if that was the issue.

Although that would have been an issue if we didn't have access, in this case it didn't fix it.

Thanks all the same.

This article has been dead for over six months. Start a new discussion instead.