PDA

Click to See Complete Forum and Search --> : CryptoAPI CertEnumCertificatesInStore usage


tbyprogram
Oct 31st, 2001, 08:56 AM
I'm trying to use the cryptoapi for signing messages and I do not think I have enough understanding of how to do this yet, perhaps someone can help here.

I have used the api to encrypt, decrypt, hash and generate/export a publickey blob successfully for practice, but I'm getting errors when calling CertEnumCertificatesInStore. I'm doing something like this:

Private Declare Function CertOpenSystemStore Lib "Crypt32.dll" Alias "CertOpenSystemStoreA" _
(ByVal hCryptProv As Long, _
ByVal pvFindPara As String) As Long

Private Declare Function CertEnumCertificatesInStore Lib "Crypt32.dll" _
(ByVal hCertStore As Long, _
ByVal pPrevCertContext As Long) As Long

strTempToo = "System"
strTemp = "MyCerts"
localHStore = CertOpenSystemStore(hCryptProv, strTemp)


lngReturn = CertEnumCertificatesInStore(localHStore, lngPointerCertContext)


Keep in mind I've tried this all sorts of ways, by changing the parameter declarations around different ways ... ( easter egging )

Setting lngPointerCertContext = vbNullString gives a type mismatch error and setting it to null or 0 causes access violation.


CertEnumCertificatesInStore's second parameter is listed as a pointer to a cert_context structure and I've tried making that type and passing it in different ways. Has anyone had success with this?

The way I understand my CSP ( MS enhanced Provider in my case ) has my public cert and associated private key in the registry. I'm assuming I need the certificate so I can get access to the associated private key?

Or do I use CryptAquireContext and specifiy the keycontainer name ( how do I find out the name to use? ) and the CSP gets the keycontainer specified? Then do I just use CryptSignHash and the private key is used?

I've got a lot of questions, but I don't want to fill the page. If anyone responds I'll just continue from there, thanks in advance.