CryptAcquireContextA fails in C++ CLR for “Aloaha Cryptographic Provider”

喜欢而已 提交于 2019-12-13 05:18:26

问题


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.


回答1:


If it works when single-stepping, it's probably a race condition (you're paused in the debugger long enough for some other process or driver to make progress).

Does it matter how much code you single-step through? Does putting a Sleep instead of a breakpoint right before the CryptAcquireContextA call also work?



来源:https://stackoverflow.com/questions/8667129/cryptacquirecontexta-fails-in-c-clr-for-aloaha-cryptographic-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!