WTHelperGetFileHash function

[The WTHelperGetFileHash function is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions.]

The WTHelperGetFileHash function verifies the signature of a signed file and obtains the hash value and algorithm identifier for the file.

Note

This function is not declared in a published header file. To use this function, declare it in the exact format shown. This function also has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.

 

Syntax

LONG WINAPI WTHelperGetFileHash(
  _In_        LPCWSTR pwszFilename,
  _In_        DWORD   dwFlags,
  _Inout_opt_ PVOID   pvReserved,
  _Out_opt_   BYTE    *pbFileHash,
  _Inout_opt_ DWORD   *pcbFileHash,
  _Out_opt_   ALG_ID  *pHashAlgid
);

Parameters

pwszFilename [in]

A pointer to a null-terminated Unicode string that contains the path and file name of the file to get the hash for.

dwFlags [in]

This parameter is not used and should be zero.

pvReserved [in, out, optional]

This parameter is not used and should be NULL.

pbFileHash [out, optional]

A pointer to a buffer to receive the hash value for the file. The pcbFileHash parameter contains the size of this buffer.

pcbFileHash [in, out, optional]

A pointer to a DWORD variable that, on input, contains the size, in bytes, of the pbFileHash buffer and, on output, receives the size, in bytes, of the hash value.

To obtain the required size of the hash value, pass NULL for the pbFileHash parameter. This function will place the required size, in bytes, of the hash value in this location.

If the pbFileHash parameter is not NULL, and the size is not large enough to receive the hash value, this function will place the required size, in bytes, in this location and return ERROR_MORE_DATA.

pHashAlgid [out, optional]

A pointer to an ALG_ID variable to receive the identifier of the algorithm used to create the hash value. This parameter can be NULL if this information is not needed.

Return value

Returns a status code that indicates the success or failure of the function.

Possible return codes include, but are not limited to, the following.

Return code Description
ERROR_SUCCESS
The file is signed, and the signature was verified.
ERROR_MORE_DATA
The pbFileHash parameter is not NULL, and the size specified by the pcbFileHash parameter is not large enough to receive the hash.
ERROR_NOT_ENOUGH_MEMORY
A memory allocation failure occurred.
TRUST_E_BAD_DIGEST
The signature of the file was not verified.
TRUST_E_NOSIGNATURE
The file was not signed or had a signature that is not valid.

 

Requirements

Requirement Value
Minimum supported client
Windows XP [desktop apps only]
Minimum supported server
Windows Server 2003 [desktop apps only]
DLL
Wintrust.dll