문서 서명
이 항목에서는 XPS 문서에 서명하는 방법을 설명합니다.
프로그램에서 다음 코드 예제를 사용하기 전에 Common Digital Signature Programming Tasks의 고지 사항을 읽어 줍니다.
XPS 문서에 서명하려면 먼저 서명 관리자 초기화에 설명된 대로 서명 관리자에 로드합니다.
서명 관리자에 로드된 문서에 서명하려면 다음을 수행합니다.
- IXpsSigningOptions 인터페이스를 인스턴스화 합니다 .
- 서명 정책을 설정합니다.
- 서명 메서드를 설정합니다. Signature 메서드 URI 문자열 상수는 cryptxml.h에 정의됩니다. 유효한 서명 메서드 값에 대한 자세한 내용은 IXpsSigningOptions::SetSignatureMethod를 참조하세요.
- 다이제스트 메서드를 설정합니다. Digest 메서드 URI 문자열 상수는 cryptxml.h에 정의됩니다. 유효한 다이제스트 메서드 값에 대한 자세한 내용은 IXpsSigningOptions::SetDigestMethod를 참조하세요.
- 파일에서 인증서 로드에 설명된 대로 인증서를 로드합니다.
- 인증서가 서명 메서드를 지원하는지 확인에 설명된 대로 인증서가 서명 메서드를 지원하는지 확인합니다.
- 시스템이 다이제스트 메서드를 지원하는지 확인에 설명된 대로 시스템에서 다이제스트 메서드를 지원하는지 확인합니다.
- 필요한 경우 문서에 인증서 체인 포함에 설명 된 대로 XPS 문서에 인증서 신뢰 체인의 인증서를 포함합니다.
- XPS 문서에 서명합니다.
다음 코드 예제에서는 프로그램에서 이전 단계를 사용하는 방법을 보여 줍니다.
// this example requires:
// cryptxml.h
// and refers to local methods that are described
// in other topics
HRESULT hr = S_OK;
BOOL supported = FALSE;
BOOL succeeded = FALSE;
IXpsSigningOptions *signingOptions = NULL;
IXpsSignature *signature = NULL;
PCCERT_CONTEXT certificate = NULL;
// Instantiate an IXpsSigningOptions interface.
hr = signatureManager->CreateSigningOptions (&signingOptions);
if (SUCCEEDED(hr)) {
// Set the signing policy to indicate the document parts
// to sign.
hr = signingOptions->SetPolicy (XPS_SIGN_POLICY_CORE_PROPERTIES);
}
if (SUCCEEDED(hr)) {
// Set the digital signature method to use to generate the
// signature hash value.
//
// The signature method used in this example is
// defined in cryptxml.h.
hr = signingOptions->SetSignatureMethod (
wszURI_XMLNS_DIGSIG_RSA_SHA1);
}
if (SUCCEEDED(hr)) {
// Set the digest method to use.
//
// The digest method used in this example is
// defined in cryptxml.h.
hr = signingOptions->SetDigestMethod (wszURI_XMLNS_DIGSIG_SHA1);
}
if (SUCCEEDED(hr)) {
// Load a certificate from a certificate file
hr = LoadCertificateFromFile (signingCertificate, &certificate);
}
if (SUCCEEDED(hr)) {
// Verify the certificate supports the digest method
supported = SupportsDigestAlgorithm (
wszURI_XMLNS_DIGSIG_SHA1);
if (!supported) hr = E_FAIL;
}
if (SUCCEEDED(hr)) {
// Verify the signature method is supported by the certificate
// and the system
supported = SupportsSignatureAlgorithm(
wszURI_XMLNS_DIGSIG_RSA_SHA1, certificate);
if (!supported) hr = E_FAIL;
}
if (SUCCEEDED(hr)) {
// Embed the certificate trust chain in the XPS package (optional).
hr = EmbedCertificateChainInXpsPackage (signingOptions, certificate);
}
if (SUCCEEDED(hr)) {
// Sign the XPS document
hr = signatureManager->Sign (signingOptions, certificate, &signature);
}
//<Free the certificate context
if (NULL != certificate) CertFreeCertificateContext (certificate);
if (NULL != signingOptions) signingOptions->Release();
if (NULL != signature) signature->Release();
관련 항목
-
다음 단계
-
이 섹션에서 사용됨
-
상세 설명