This article describes how to use the Microsoft CAPI interface to complete the registration of a certificate in Usbkey to a Windows system.
(1) Gets the CSP handle.
CryptAcquireContext (
&htokenprov,null,
"Entersafe Et199auto CSP V1.0",
Prov_rsa_full,
NULL)
(2) To get the key handle inside the Usbkey, note that the type of the key inside the lock is the signature key (At_signature) or the Exchange key (At_keyexchange).
Cryptgetuserkey (HTOKENPROV,AT_KEYEXCHANGE,&HKEYCAPI)
(3) Obtain the certificate data (only the certificate information data, not including the private key), at this time can be called two times, first obtain the length of the certificate data, allocate space, and then called again.
CryptGetKeyParam (Hkeycapi, Kp_certificate, Pbcert, &dwcertlen, 0)
(4) Create CERT_CONTEXT structure
Pcertcontext = CertCreateCertificateContext (
pkcs_7_asn_encoding | X509_asn_encoding,
Pbcert,
Dwcertlen)
(5) Open My store, this is the area where the "personal" certificate is stored in the Windows system.
Hsysstore = CertOpenStore (
Cert_store_prov_system_registry,
0,
0,
Cert_system_store_current_user,
L "MY");
(6) Set the certificate context properties. You declare the CRYPT_KEY_PROV_INFO structure first.
Crypt_key_prov_info Ckpi = {0};
Ckpi.pwszprovname = L "Entersafe et199auto CSP V1.0";
Ckpi.pwszcontainername = Pbwidecontainer;
Ckpi.dwprovtype = Prov_rsa_full;
Ckpi.dwkeyspec = At_keyexchange;
Ckpi.dwflags = cert_key_context_prop_id;
Ckpi.cprovparam = 0;
Ckpi.rgprovparam = NULL;
Certsetcertificatecontextproperty (
Pcertcontext,
cert_key_prov_info_prop_id, Cert_store_no_crypt_release_flag,
&CKPI)
(7) Register the certificate with the Windows system.
Certaddcertificatecontexttostore (
Hsysstore,
Pcertcontext,
Cert_store_add_replace_existing,
NULL);
(8) Releases the CSP handle.
CryptReleaseContext (htokenprov,0)
The above steps allow you to register the certificate in Et199auto with the Windows system. Can we be in IE? Internet Options? What is the certificate? Individual below to view the certificate in Et199auto.
How to register a certificate in Usbkey to a Windows system