I am trying to sign using a certificate in a WatchData USB token. I use the Microsoft CryptoAPI function CryptSignMessage. If I specifiy sha1 as the Hashing Algorithm for the signing, then it succeeds. However this fails with an "Internal Error has occurred" if I try to use sha256.
The driver is downloaded from http://www.watchdata.com/service/usbtoken.jsp. This contains the PKCS#11 provider.
As per http://blogs.msdn.com/b/alejacma/archive/2010/06/02/quot-an-internal-error-ocurred-quot-when-using-sha-2-algorithms-with-signedcms.aspx this is because the WatchData Provider is not a CNG provider - (Cryptography API: Next Generation).
The call to NCryptOpenStorageProvider fails with the following program - which seems to show that it's not a CNG Provider.
#include <windows.h>
#include <stdio.h>
#include <ncrypt.h>
int main()
{
NCRYPT_PROV_HANDLE hProv;
SECURITY_STATUS ret = NCryptOpenStorageProvider(&hProv,
L"Watchdata Brazil CSP v1.0", 0);
if( ret != ERROR_SUCCESS)
printf("Failed\n");
else
printf("worked\n");
}
I found the name of the provider by calling the CryptEnumProviders API.
Is there any other way to sign RSA-Sha256 using the certificate on the WatchData token? I would think there is no need for the CryptoAPI to rely on the CSP for the hashing function. Hashing is a standard function & CryptoAPI does have implementation of SHA-2.