CryptCATAdminCalcHashFromFileHandle2 function (mscat.h)

The CryptCATAdminCalcHashFromFileHandle2 function calculates the hash for a file by using the specified algorithm.

This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.

Syntax

BOOL CryptCATAdminCalcHashFromFileHandle2(
  [in]      HCATADMIN hCatAdmin,
  [in]      HANDLE    hFile,
  [in, out] DWORD     *pcbHash,
            BYTE      *pbHash,
            DWORD     dwFlags
);

Parameters

[in] hCatAdmin

Handle of an open catalog administrator context. For more information, see CryptCATAdminAcquireContext2.

[in] hFile

A handle to the file whose hash is being calculated. This parameter cannot be NULL and must be a valid file handle.

[in, out] pcbHash

Pointer to a DWORD variable that contains the number of bytes in the pbHash parameter. Upon input, set pcbHash to the number of bytes allocated for pbHash. Upon return, pcbHash contains the number of returned bytes in pbHash. If pbHash is set to NULL, then pcbHash contains the number of bytes to allocate for pbHash.

pbHash

Pointer to a BYTE buffer that receives the hash. If you set this parameter to NULL, then pcbHash will contain the number of bytes to allocate for pbHash, and a subsequent call can be made to retrieve the hash.

dwFlags

Reserved. This value must be zero.

Return value

If the function succeeds, the return value is nonzero (TRUE).

If the function fails, the return value is zero (FALSE). For extended error information, call GetLastError.

The following table lists the error codes most commonly returned by the GetLastError function.

Return code Description
ERROR_INVALID_PARAMETER
The hFile parameter must not be NULL.

The hFile parameter must be a valid file handle.

The pcbHash parameter must not be NULL.

The dwFlags parameter must be zero (0).

ERROR_INSUFFICIENT_BUFFER
The buffer pointed to by the pbHash parameter was not NULL but was not large enough to be written. The correct size of the required buffer is contained in the value pointed to by the pcbHash parameter.
NTE_BAD_ALGID
The hash algorithm specified by the pwszHashAlgorithm parameter cannot be found.

Remarks

The amount of time this function takes to execute depends on the length of the file being hashed, the algorithm being used, and the file location. For example, it takes several seconds to calculate the hash of a local file that is very large (a few hundred megabytes).

Requirements

Requirement Value
Minimum supported client Windows 8 [desktop apps only]
Minimum supported server Windows Server 2012 [desktop apps only]
Target Platform Windows
Header mscat.h
Library Wintrust.lib
DLL Wintrust.dll

See also

CryptCATAdminCalcHashFromFileHandle

CryptCATAdminCalcHashFromFileHandle2