Search code examples
c++cryptographydigital-signaturecryptoapiocx

Use key / certificate on ukey to sign data


I want to get certificate from ukey, and sign data. Now I can get it, and succeeded in a console application program. But when I make it as an OCX control for Internet Explorer then it doesn't work.

When I use the following function:

CryptAcquireContext(&hProvder, NULL, my_provder_name, PROV_RSA_FULL, 0)

it fails, returning nte_bad_keyset.

When I use CRYPT_NEWKEYSET or CRYPT_MACHINE_KEYSET instead of 0, signing the data fails.

How can I create a signature using ukey?


Solution

  • CryptAcquireContext(&hProvder, NULL, my_provder_name, PROV_RSA_FULL, 0);

    You want to get the csp which could be helpful for signature your file.In a desktop application,you can use the function with those parameters like that case.But in browser,you can't. we want to get the default key container associated with the current user. Howerver, when certificates are created, they may be placed in a key container other than the default, so the default container doesn't exist. why? The problem appears to stem from the second parameter. So, we must specify the name of key container as the second parameter. Like this: CryptAcquireContext(&hProvder, container_name, my_provder_name, PROV_RSA_FULL, 0);