시스템이 다이제스트 메서드를 지원하는지 확인
이 항목에서는 시스템에서 다이제스트 메서드를 지원하는지 확인하는 방법을 설명합니다.
XPS 디지털 서명은 시스템에서 특정 다이제스트 메서드를 지원하는지 확인하는 메서드를 제공하는 Crypto API를 사용합니다. Crypto API의 CryptXmlEnumAlgorithmInfo 함수를 사용하여 시스템에서 지원하는 다이제스트 메서드를 열거하려면 호출자가 콜백 메서드와 데이터 구조를 제공해야 합니다. CryptXmlEnumAlgorithmInfo 함수는 콜백 메서드를 통해 열거형 데이터를 호출자에게 다시 전달합니다.
이 예제에 사용된 데이터 구조는 다음 코드 예제에 나와 있으며 다음 필드를 포함합니다.
필드 | 설명 |
---|---|
userDigestAlgorithm | 검사 다이제스트 알고리즘의 URI가 포함된 문자열을 가리키는 LPWSTR 필드입니다. |
userDigestAlgorithmSupported | 다이제스트 알고리즘이 인증서에서 지원되는지 여부를 나타내는 부울 값입니다. |
struct DigestMethodData
{
LPCWSTR userDigestAlgorithm;
BOOL userDigestAlgorithmSupported;
};
다이제스트 메서드를 열거하는 Crypto API 메서드는 콜백 메서드를 사용하여 호출자에게 데이터를 반환합니다. CryptXmlEnumAlgorithmInfo는 시스템에서 지원하는 다이제스트 메서드를 열거하고 콜백 메서드가 FALSE를 반환하거나 시스템에서 지원하는 모든 다이제스트 메서드가 열거될 때까지 열거하는 각 다이제스트 메서드에 대해 콜백 메서드를 호출합니다. 이 예제의 콜백 메서드는 CryptXmlEnumAlgorithmInfo에 의해 전달되는 다이제스트 메서드와 호출 메서드에서 제공하는 다이제스트 메서드를 비교합니다.
BOOL WINAPI
EnumDigestMethodCallback (
__in const CRYPT_XML_ALGORITHM_INFO *certMethodInfo,
__inout_opt void *userArg
)
{
// MAX_ALG_ID_LEN is used to set the maximum length of the
// algorithm URI in the string comparison. The URI is not
// likely to be longer than 128 characters so a fixed-size
// buffer is used in this example.
// To make this function more robust, consider
// setting this value dynamically.
static const size_t MAX_ALG_ID_LEN = 128;
DigestMethodData *certificateAlgorithmData =
(DigestMethodData*)userArg;
if (NULL != userArg) {
// Assign user data to local data structure
certificateAlgorithmData = (DigestMethodData*)userArg;
} else {
// Unable to continue this enumeration without
// data from calling method.
return FALSE;
}
// For each algorithm in the enumeration, check to see
// if the URI of the current supported algorithm matches
// the URI passed in userArg.
int cmpResult = 0;
cmpResult = wcsncmp(
certMethodInfo->wszAlgorithmURI,
certificateAlgorithmData->userDigestAlgorithm,
MAX_ALG_ID_LEN );
if ( 0 == cmpResult )
{
// This is a match...
// set supported value to true
certificateAlgorithmData->userDigestAlgorithmSupported = TRUE;
// ...and return FALSE to stop any further enumeration
return FALSE;
}
else
{
// no match was found
// return TRUE to continue enumeration
return TRUE;
}
}
다음 코드 샘플은 유효성 검사 기능을 단일 메서드로 래핑합니다. 이 메서드는 시스템에서 다이제스트 메서드를 지원하는지 여부를 나타내는 부울 값을 반환합니다.
BOOL
SupportsDigestAlgorithm (
__in LPCWSTR digestMethodToCheck
)
{
HRESULT hr = S_OK;
// Initialize the structure that will hold information about the
// digest method to check
DigestMethodData certificateAlgorithmData;
certificateAlgorithmData.userDigestAlgorithmSupported = FALSE;
certificateAlgorithmData.userDigestAlgorithm = digestMethodToCheck;
// Enumerate the algorithms that are supported on the system,
// the callback method compares each supported algorithm to the one
// passed in digestMethodToCheck and returns true in the
// certificateAlgorithmData.userDigestAlgorithmSupported field if
// the provided digest algorithm is supported by system.
//
// Note that CRYPT_XML_GROUP_ID_HASH is set to enumerate
// digest methods
hr = CryptXmlEnumAlgorithmInfo(
CRYPT_XML_GROUP_ID_HASH, // NOTE: CRYPT_XML_GROUP_ID_HASH
CRYPT_XML_FLAG_DISABLE_EXTENSIONS,
(void*)&certificateAlgorithmData,
EnumDigestMethodCallback);
return certificateAlgorithmData.userDigestAlgorithmSupported;
}
관련 항목
-
다음 단계
-
이 예제에서 사용됨
-
CryptXmlEnumAlgorithmInfo
-
상세 설명