怎样给WebBrowser通过InternetSetOption选择证书
答案:1 悬赏:0 手机版
解决时间 2021-02-19 16:29
- 提问者网友:我是我
- 2021-02-19 03:30
怎样给WebBrowser通过InternetSetOption选择证书
最佳答案
- 五星知识达人网友:夜风逐马
- 2021-02-19 05:01
运行错误,错误码:
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE (INTERNET_ERROR_BASE + 18)
代码如下:
LPWSTR pswzFirstCert = L"sss";// Subject of the first
// certificate.
HCERTSTORE hSystemStore; // The system store handle
PCCERT_CONTEXT pDesiredCert;
pDesiredCert = NULL;
if(hSystemStore = CertOpenStore(
CERT_STORE_PROV_SYSTEM, // The system store will be a
// virtual store.
0, // Encoding type not need with this PROV.
NULL, // Accept the default HCRYPTPROV.
CERT_SYSTEM_STORE_CURRENT_USER,
L"ROOT")) // System store name.//MY CA ROOT SPC 四种
{
printf("Opened the MY system store. \n");
}
else
{
}
//-------------------------------------------------------------------
// Get a certificate that has the string "Full Test Cert" in its subject.
if(pDesiredCert)
CertFreeCertificateContext(pDesiredCert);
if(pDesiredCert=CertFindCertificateInStore(
hSystemStore,
X509_ASN_ENCODING, // Use X509_ASN_ENCODING.
0, // No dwFlags needed.
CERT_FIND_SUBJECT_STR, // Find a certificate with a
// subject that matches the string
// in the next parameter.
pswzFirstCert, // The Unicode string to be found
// in a certificate's subject.
NULL)) // NULL is used so that the
// search will begin at the
// beginning of the certificate
// store.
{
printf("The %S certificate was found. \n",pswzFirstCert);
}
else
{
printf("The %S certificate was not found. \n",pswzFirstCert);
}
if(hSystemStore)
CertCloseStore(hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG);
if( InternetSetOption (0, INTERNET_OPTION_CLIENT_CERT_CONTEXT,
(LPVOID)pDesiredCert, sizeof (CERT_CONTEXT) ) == FALSE )
{
int i = GetLastError();
printf("InternetSetOption failed with error %d. \n",i);
}
if(pDesiredCert) CertFreeCertificateContext(pDesiredCert);
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE (INTERNET_ERROR_BASE + 18)
代码如下:
LPWSTR pswzFirstCert = L"sss";// Subject of the first
// certificate.
HCERTSTORE hSystemStore; // The system store handle
PCCERT_CONTEXT pDesiredCert;
pDesiredCert = NULL;
if(hSystemStore = CertOpenStore(
CERT_STORE_PROV_SYSTEM, // The system store will be a
// virtual store.
0, // Encoding type not need with this PROV.
NULL, // Accept the default HCRYPTPROV.
CERT_SYSTEM_STORE_CURRENT_USER,
L"ROOT")) // System store name.//MY CA ROOT SPC 四种
{
printf("Opened the MY system store. \n");
}
else
{
}
//-------------------------------------------------------------------
// Get a certificate that has the string "Full Test Cert" in its subject.
if(pDesiredCert)
CertFreeCertificateContext(pDesiredCert);
if(pDesiredCert=CertFindCertificateInStore(
hSystemStore,
X509_ASN_ENCODING, // Use X509_ASN_ENCODING.
0, // No dwFlags needed.
CERT_FIND_SUBJECT_STR, // Find a certificate with a
// subject that matches the string
// in the next parameter.
pswzFirstCert, // The Unicode string to be found
// in a certificate's subject.
NULL)) // NULL is used so that the
// search will begin at the
// beginning of the certificate
// store.
{
printf("The %S certificate was found. \n",pswzFirstCert);
}
else
{
printf("The %S certificate was not found. \n",pswzFirstCert);
}
if(hSystemStore)
CertCloseStore(hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG);
if( InternetSetOption (0, INTERNET_OPTION_CLIENT_CERT_CONTEXT,
(LPVOID)pDesiredCert, sizeof (CERT_CONTEXT) ) == FALSE )
{
int i = GetLastError();
printf("InternetSetOption failed with error %d. \n",i);
}
if(pDesiredCert) CertFreeCertificateContext(pDesiredCert);
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯