in the GetCertContainernames() method.
loop) work properly.
"Mitch Gallant" <jensigner@community.nospam> wrote in message news:eOLfiGLPGHA.344@TK2MSFTNGP11.phx.gbl...
> Forgot to add that the native error on 2nd (failed) invocation of
> CertGetCertificateContextProperty(..)
> is
> Error code: 0x80004005
> Error message: The data is invalid
>
> - Mitch
>
> "Mitch Gallant" <jensigner@community.nospam> wrote in message news:O1Q$82KPGHA.1288@TK2MSFTNGP09.phx.gbl...
>> There is a problem in this KeyPal .NET application:
>>
http://www.jensign.com/JavaScience/dotnet/keypal >>
>> This application uses Pinvoke to CryptoAPI to enumerate
>> capi keycontainers and detect which certs in the MY store
>> have an associated private key. SOurce code is at:
>>
http://www.jensign.com/JavaScience/dotnet/keypal/source/KeyPal.txt >>
>> The problem seems to be in the following method:
>> private static Hashtable GetCertContainernames()
>>
>> When this method is invoked a *second* time (from the R or Refresh
>> keyboard command in the app), the function called during the
>> certificate store enumeration:
>>
>> Win32.CertGetCertificateContextProperty
>> (hCertCntxt, CERT_KEY_PROV_INFO_PROP_ID, IntPtr.Zero, ref provinfosize))
>>
>> does not return the correct result for one cert that DOES have a private key.
>> The initial display however does return the correct result.
>>
>> I think all the proper memory is being freed. Can anyone spot some code-problem?
>> It is reproducible (correct result on initial display of key/cert results, but misses
>> one certificate with private key on successive Refresh calls to that function.
>>
>> - Mitch Gallant
>> MVP Security
>>
>>
>>
>>
>
>