다음을 통해 공유


문서 서명

이 항목에서는 XPS 문서에 서명하는 방법을 설명합니다.

프로그램에서 다음 코드 예제를 사용하기 전에 Common Digital Signature Programming Tasks고지 사항을 읽어 줍니다.

XPS 문서에 서명하려면 먼저 서명 관리자 초기화에 설명된 대로 서명 관리자로드합니다.

서명 관리자에 로드된 문서에 서명하려면 다음을 수행합니다.

  1. IXpsSigningOptions 인터페이스를 인스턴스화 합니다 .
  2. 서명 정책을 설정합니다.
  3. 서명 메서드를 설정합니다. Signature 메서드 URI 문자열 상수는 cryptxml.h에 정의됩니다. 유효한 서명 메서드 값에 대한 자세한 내용은 IXpsSigningOptions::SetSignatureMethod를 참조하세요.
  4. 다이제스트 메서드를 설정합니다. Digest 메서드 URI 문자열 상수는 cryptxml.h에 정의됩니다. 유효한 다이제스트 메서드 값에 대한 자세한 내용은 IXpsSigningOptions::SetDigestMethod를 참조하세요.
  5. 파일에서 인증서 로드에 설명된 대로 인증서를 로드합니다.
  6. 인증서가 서명 메서드를 지원하는지 확인에 설명된 대로 인증서가 서명 메서드를 지원하는지 확인합니다.
  7. 시스템이 다이제스트 메서드를 지원하는지 확인에 설명된 대로 시스템에서 다이제스트 메서드를 지원하는지 확인합니다.
  8. 필요한 경우 문서에 인증서 체인 포함에 설명 된 대로 XPS 문서에 인증서 신뢰 체인의 인증서를 포함합니다.
  9. 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();

다음 단계 

XPS 문서에 서명 요청 추가

문서 서명 확인

이 섹션에서 사용됨

CertFreeCertificateContext

IXpsSignatureManager

IXpsSignatureManager::CreateSigningOptions

IXpsSignatureManager::Sign

IXpsSigningOptions

IXpsSigningOptions::SetDigestMethod

IXpsSigningOptions::SetPolicy

IXpsSigningOptions::SetSignatureMethod

XPS_SIGN_POLICY

상세 설명

암호화 API

암호화 함수

파일에서 인증서 로드

인증서가 서명 방법을 지원하는지 확인

시스템이 다이제스트 메서드를 지원하는지 확인

문서에 인증서 체인 포함

XPS 디지털 서명 API 오류

XPS 문서 오류

XML Paper Specification