由 Windows 生物识别框架调用,以选择用于后续操作的哈希算法。
语法
PIBIO_ENGINE_SET_HASH_ALGORITHM_FN PibioEngineSetHashAlgorithmFn;
HRESULT PibioEngineSetHashAlgorithmFn(
  [in, out] PWINBIO_PIPELINE Pipeline,
  [in]      SIZE_T AlgorithmBufferSize,
  [in]      PUCHAR AlgorithmBuffer
)
{...}
参数
[in, out] Pipeline
指向与执行操作的生物识别单元关联的 WINBIO_PIPELINE 结构的指针。
[in] AlgorithmBufferSize
AlgorithmBuffer 参数指定的缓冲区的大小(以字节为单位)。
[in] AlgorithmBuffer
指向以 NULL 结尾的 ANSI 字符串的指针,该字符串包含要选择的哈希算法的对象标识符。 调用 EngineAdapterQueryHashAlgorithms 函数以检索受支持算法对象标识符的数组 (OID) 。
返回值
如果函数成功,则返回S_OK。 如果函数失败,它必须返回以下 HRESULT 值之一来指示错误。
| 返回代码 | 说明 | 
|---|---|
  | 
强制指针参数为 NULL。 | 
  | 
引擎适配器不支持模板哈希。 | 
  | 
引擎适配器不支持 AlgorithmBuffer 参数指定的哈希算法。 | 
注解
Windows 生物识别框架调用此函数,以在每次将单元添加到传感器池时配置生物识别单元。
由于哈希算法是按管道选择的,因此引擎适配器必须将所选算法存储在专用管道上下文中。
引擎适配器必须跟踪所选的最新算法,并在处理对以下函数的调用时使用此算法:
此函数选择的算法必须保持选中状态,直到下次调用 EngineAdapterSetHashAlgorithm ,或直到调用 EngineAdapterDetach 方法。 具体而言,对 EngineAdapterClearContext 函数的调用不应影响所选算法。Windows 生物识别框架仅使用 SHA1 哈希算法。 此算法的 OID 字符串值为“1.3.14.3.2.26”。 有关详细信息,请参阅 EngineAdapterQueryHashAlgorithms。
示例
以下伪代码演示了此函数的一种可能实现。 该示例不编译。 必须根据自己的目的调整它。
//////////////////////////////////////////////////////////////////////////////////////////
//
// EngineAdapterSetHashAlgorithm
//
// Purpose:
//      Selects a hash algorithm for use in subsequent operations.
//
// Parameters:
//      Pipeline            - Pointer to a WINBIO_PIPELINE structure associated 
//                            with the biometric unit performing the operation.   
//      AlgorithmBufferSize - Size, in bytes, of the buffer specified by the 
//                            AlgorithmBuffer parameter.
//      AlgorithmBuffer     - Pointer to a NULL-terminated ANSI string that 
//                            contains the object identifier of the hash algorithm
//                            to select.
//
static HRESULT
WINAPI
EngineAdapterSetHashAlgorithm(
    __inout PWINBIO_PIPELINE Pipeline,
    __in SIZE_T AlgorithmBufferSize,
    __in PUCHAR AlgorithmBuffer
    )
{
    ////////////////////////////////////////////////////////////////////////////
    // Return E_NOTIMPL here if your adapter does not support template hashing.
    ////////////////////////////////////////////////////////////////////////////
    HRESULT hr = S_OK;
    SIZE_T algorithmSize = (strlen(szOID_OIWSEC_sha1) + 1) * sizeof(CHAR);
    // Verify that pointer arguments are not NULL.
    if (!ARGUMENT_PRESENT(Pipeline) ||
        !ARGUMENT_PRESENT(AlgorithmBuffer))
    {
        hr = E_POINTER;
        goto cleanup;
    }
    // Only the SHA1 hashing algorithm is supported.
    // Therefore, make certain that SHA1 is included in the algorithm
    // table.
    // The SHA1 object identifier, szOID_OIWSEC_sha1, is contained in the
    // Wincrypt.h header file.
    if (AlgorithmBufferSize != algorithmSize ||
        memcmp(AlgorithmBuffer, szOID_OIWSEC_sha1, algorithmSize) != 0)
    {
        hr = E_INVALIDARG;
        goto cleanup;
    }
    // Make any necessary changes to the adapter state to specify that
    // SHA1 hashing is enabled. If your adapter does not support template
    // hashing, return E_NOTIMPL.
cleanup:
    
    return hr;
}
要求
| 要求 | 值 | 
|---|---|
| 最低受支持的客户端 | Windows 7 [仅限桌面应用] | 
| 最低受支持的服务器 | Windows Server 2008 R2 [仅限桌面应用] | 
| 目标平台 | Windows | 
| 标头 | winbio_adapter.h (包括 Winbio_adapter.h) |