How to enum CSPs in C#?

  • Thread starter Thread starter mRbEn
  • Start date Start date
M

mRbEn

Hi:
I'm trying to write a web page by using c# under dotnet framwork. My target
is lets the user to choose a csp to get a certificate from CA. But, I only
know how to enum providers by cryptoapi like: CryptEnumProviders(...).
Who can tell me how to enum csps by using C#?
thanks
 
Brendan,

That's pretty funky. How did you know it was me who posted it? =)
 
one more question!
When I call the cryptenumproviders in my C# project. I got an error it's
said that the module could not be found. Why can't my project load
advapi32.dll and find the module CryptEnumProviders ? !!!
 
mRbEn,

What does the declaration in your code look like? You arent setting a
reference to advapi32.dll, are you?
 
I do think so, too. But I don't know how to reference to it.It's seemed I
can't reference to it by using the reference windows in my project.
BTW, APIs imported from User32 and Kenerl32 are worked well.

[DllImport("user32.dll", EntryPoint="MessageBox")]
public static extern int MsgBox(int hWnd, String text, String caption,
uint type);
above is right.

[DllImport("Advapi32", EntryPoint="CryptEnumProvidersW",
SetLastError=true, ExactSpelling=true,
CharSet=CharSet.Auto)]
static extern bool CryptEnumProviders(
[MarshalAs(UnmanagedType.U4)] int dwIndex,
[MarshalAs(UnmanagedType.U4)] ref int pdwReserved,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
[MarshalAs(UnmanagedType.U4)] ref int pdwProvType,
StringBuilder pszProvName,
[MarshalAs(UnmanagedType.U4)] ref int pcbProvName);
above is wrong.
errcode=126 ERROR_MOD_NOT_FOUND
The specified module could not be found.


Nicholas Paldino said:
mRbEn,

What does the declaration in your code look like? You arent setting a
reference to advapi32.dll, are you?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

mRbEn said:
one more question!
When I call the cryptenumproviders in my C# project. I got an error it's
said that the module could not be found. Why can't my project load
advapi32.dll and find the module CryptEnumProviders ? !!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top