How to fix Exception Message: Windows cannot verify the digital signature for this file.

Nevin Sunny 0 Reputation points
2023-09-22T19:39:35.97+00:00

I have a signed exe which was being signed using a certificate present on the device and now moved to signing using Java.

User's image

The exe is responsible for toggling Windows Firewall, but after signing with my new certificate, I am getting this error

"Exception Message: Windows cannot verify the digital signature for this file. A recent hardware or software change might have installed a file that is signed incorrectly or damaged, or that might be malicious software from an unknown source "

The certificate seems to be ok here,

User's image

But when running it, throws Win32 exception.

I believe it is throwing error here in the code. Any help on this would be appreciated.

Thank you.

HCRYPTPROV hProvider;
		if (!CryptAcquireContextA(&hProvider, NULL, NULL, PROV_RSA_AES, CRYPT_SILENT) &&
			(GetLastError() != NTE_BAD_KEYSET || // keyset not found, try to make a new one
				!CryptAcquireContextA(&hProvider, NULL, NULL, PROV_RSA_AES, CRYPT_NEWKEYSET)))
		{
			hr = HRESULT_FROM_WIN32(GetLastError());
			DBG_PRINT(4, hr);
			return hr | 0x04000000;
		}	

Windows for business Windows Client for IT Pros User experience Other
Developer technologies C++
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.