Platform SDK: Certificate Enrollment Control

ICEnroll3::EnumAlgs [C++]

CEnroll.EnumAlgs [Visual Basic]

The EnumAlgs method enumerates the IDs of cryptographic algorithms supported by the current cryptographic service provider (CSP).

[Visual Basic]
objEnroll.EnumAlgs( _
            dwIndex As Long, _
            algClass As Long ) As Long
[C++]
HRESULT EnumAlgs(
  DWORD   dwIndex,
  DWORD   algClass,
  DWORD*  pdwAlgID
);

Parameters

[Visual Basic] objEnroll
Object expression that resolves to a CEnroll object.
[Visual Basic,C++]dwIndex
Zero-based index of the algorithm ID to enumerate.
[Visual Basic,C++]algClass
Value representing a cryptographic algorithm class. This can be any one of the following:
[C++] pdwAlgID
Upon successful completion, pointer to value representing a cryptographic algorithm (as defined in wincrypt.h) which is supported by the current CSP. For example, this value could be CALG_MD2.

Return Values

[Visual Basic] Upon successful completion, value representing a cryptographic algorithm (as defined in wincrypt.h) which is supported by the current CSP. For example, this value could be CALG_MD2. When there are no more algorithms to enumerate, the value ERROR_NO_MORE_ITEMS is returned.

[C++] The return value is an HRESULT. A value of S_OK indicates success, and *pdwAlgID will be the value of the enumerated algorithm ID. When there are no more algorithms to enumerate, the value ERROR_NO_MORE_ITEMS is returned.

Remarks

Use this method to enumerate the algorithms supported by the current CSP for a given algorithm class.

Example Code [C++]

DWORD     dwAlgID;
DWORD     dwIndex;

BSTR      bstrAlgName = NULL;

HRESULT   hr, hr2;

// Loop through the AlgIDs.
dwIndex = 0;
while ( TRUE )
{
    // Enumerate the alg IDs for a specific class.
    hr = pEnroll->EnumAlgs(dwIndex, ALG_CLASS_SIGNATURE, &dwAlgID);
    if ( S_OK != hr )
    {
       break;
    }

    // Do something with the AlgID.
    // For example, retrieve the corresponding name.
    hr2 = pEnroll->GetAlgName( dwAlgID, &bstrAlgName);
    if ( FAILED( hr2 ) )    
        printf("Failed GetAlgName [%x]\n", hr);
    else
        printf("AlgID: %d Name: %S\n", dwAlgID, bstrAlgName );

    // Reuse the BSTR variable in next iteration.
    if ( NULL != bstrAlgName )
    {
        SysFreeString( bstrAlgName );
        bstrAlgName = NULL;
    }

    // Increment the index.
    dwIndex++;
}
 

Example Code [Visual Basic]

    ' Constants representing algorithm classes.
    Const ALG_CLASS_SIGNATURE = &H2000    ' (1 << 13) in wincrypt.h
    Const ALG_CLASS_MSG_ENCRYPT = &H4000  ' (2 << 13) in wincrypt.h
    Const ALG_CLASS_DATA_ENCRYPT = &H6000 ' (3 << 13) in wincrypt.h
    Const ALG_CLASS_HASH = &H8000         ' (4 << 13) in wincrypt.h
    Const ALG_CLASS_KEY_EXCHANGE = &HA000 ' (5 << 13) in wincrypt.h
    
    ' Variables for algID and index
    Dim AlgID As Long, Index As Long
    
    ' Set the index to the first item.
    Index = 0

    On Error GoTo Err1
    ' Loop through the algorithm IDs for a specific class.
    Do
        ' objXen is a previously instantiated ICEnroll3 object.
        AlgID = objXen.EnumAlgs(Index, ALG_CLASS_DATA_ENCRYPT)
        ' Do something with the algID.
        MsgBox (objXen.GetAlgName(AlgID))
        ' Increment to next index.
        Index = Index + 1
    Loop

Err1:
    
    MsgBox ("Number of algorithm ID(s): " & Index)
 

Requirements

  Windows NT/2000: Requires Windows 2000.
  Header: Declared in Xenroll.h.
  Library: Use Uuid.lib.

See Also

ICEnroll3