通過Win32上的代碼安裝根CA證書(Installing Root CA Cert via code on Win32)

First you need to open the root certificate store...

HCERTSTORE hRootCertStore = CertOpenSystemStore(NULL,"ROOT");

Then add the certificate using one of the CertAdd functions, such as CertAddEncodedCertificateToStore.

CertAddEncodedCertificateToStore(hRootCertStore,X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,pCertData,cbCertData,CERT_STORE_ADD_USE_EXISTING,NULL);

pCertData and cbCertData would likely point to the certificate data that you read from a file (not sure if the certificate will be in a file, or how you will include it in your application).

Then close the store with...

CertCloseStore(hRootCertStore,0);

NOTE: This code if run as the user, installs the certificate to the user's root store, not the computer's. It also results in a warning dialog that the user must understand and select "Yes" to authorize the import. If your setup program can run this code in a system account, the import will affect the computer's root store and not warning dialog will be shown.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章