how to use Microsoft Crypto API with USB Dongle fo

2019-07-17 06:29发布

问题:

I have safenet authentication usb token which was given by a company and they told me they have digital public key certificate inside. They gave me a password and a software by which i can see that it can detect certificate inside. Now i need to access this token's certificate and then i need to use signing , encryption and decryption using my development code. But the company didn't gave me any sdk so i have to do everything by C++ Microsoft CryptoAPI. I searched on google but i am not sure if i am on right direction

this code doesn't give me correct handle for the usb stored certificate

        // Attempt to acquire a handle to the default key container.
        bResult = CryptAcquireContext(
                    &hProv,            // Variable to hold returned handle.
                    NULL,              // Use default key container.
                    MS_DEF_PROV,       // Use default CSP.
                    PROV_RSA_FULL,     // Type of provider to acquire.
        0);             

i thought it should give any default connected certificate either its on smart card or token. I tried MS_SCARD_PROV as well in thought if it will give me access through usb token but it seems like its just for the smart card not for token.

I am desperate to complete this task please guide me or show me correct tutorial if you experts know any. Or suggest me what should be done for such kind of task..

回答1:

you will be using both PKCS#11 and CryptoAPI functionalities.

PKCS#11 will be primarily used to talk to the hardware token. Every hardware vendor would have implemented a PKCS#11 interface for their hardware token. If your's is etoken,then safenet has one. Also safenet will have their CryptoAPI CSP that you can use to talk to the token.

CryptoAPI provides rich functionality to handle certificates that are present with in the token.