I have C++ CLR project with both managed and unmanaged code. In this project I loop through list of cryptoproviders and search for suitable.
So I use functions
CryptEnumProvidersA
CryptAcquireContextA
I have C# project which uses C++ project. When I call the method to loop through list of cryptoproviders twice, my application crashes. And it crashes on CryptAcquireContextA. And only on "Aloaha Cryptographic Provider".
When i use debug mode, it also crashes. But when i use debug mode, set breakpoint and pass through code with F10, it works fine.
When i carry out C++ code to separate project, it works fine in all cases.
So, I have two questions here:
1) How such a crash possible? And why it happens?
2) How can I call CryptAcquireContextA to handle such a crash?
My considerations.
1) Some troubles with memory. I was searching for memory leaks, but I didn't find any.
2) I tried to use try-catch, but with no result, CryptAcquireContextA crashes anyway. I would like to use function like "CryptIsValidProvider" or "CryptPingProvider", but I didn't find it.