2015-11-23 8 views
9

का उपयोग कर सीधे एक ऑफिस वर्ड दस्तावेज़ पर हस्ताक्षर कर रहा हूं, मैं सी # एक्सएमएल प्रारूप में सी # का उपयोग कर एक Microsoft Office Word फ़ाइल पर हस्ताक्षर करने का प्रयास कर रहा हूं।एक्सएमएल

कुछ सवाल हैं और ambiguousness की तरह यहां उठता है:

  • मैं डाइजेस्ट मूल्यों कैसे भरनी चाहिए, क्या मूल्य मैं बिल्कुल प्रत्येक संदर्भ के लिए पचाने चाहिए, और मैं प्रत्येक को बदलने के लिए क्या मूल्य पचाने चाहिए?
  • SignatureValue बनाने के लिए मुझे किस मूल्य पर हस्ताक्षर करना चाहिए?
  • और x509 डेटा में मुझे किस प्रमाणपत्र में शामिल करना चाहिए और कैसे? (हमारे पास प्रमाण पत्र नहीं है इसलिए एक बनाने के लिए एक गाइड की सराहना की जाती है।)

अंतिम प्रश्न यह है कि मैं इसे सही तरीके से कर रहा हूं? शायद यहां कुछ गड़बड़ है और मैंने एक पैकेज खो दिया है जो अन्यथा ओपनएक्सएमएल दस्तावेज़ से बातचीत करेगा और इसे हस्ताक्षर करेगा।

लेकिन याद रखें कि मैं वास्तव में एक बाहरी टोकन के साथ डेटा पर हस्ताक्षर करने की कोशिश कर रहा हूं जिसमें एक pkcs11 इंटरफ़ेस उपलब्ध है (लेकिन कोई सीएसपी नहीं है) इसलिए मैंने इसे PKCS11 इंटरऑप लाइब्रेरी का उपयोग C# पर माइग्रेट करने के लिए किया है, लेकिन मैं अभी भी यहां थोड़ा उलझन में है।

  • क्या कोई पैकेज है जिसका उपयोग मैं दस्तावेज़ दस्तावेज़ों पर हस्ताक्षर करने के लिए कर सकता हूं?
  • या क्या कोई पैकेज है जो openXML इंटरैक्शन को आसान बनाता है?
  • या मुझे इसे मैन्युअल रूप से करना है?
बस सिर ऊपर किसी भी पुस्तकालय भी है (यानी जो मुझे bytestream पर हस्ताक्षर और पचाने के लिए देता है, लेकिन अन्य भागों में ही करता है, pkcs11 वास्तव में है मुझे pkcs11 आदेशों का उपयोग करते दस्तावेजों पर हस्ताक्षर के लिए अनुमति चाहिए OPENXML बातचीत करता है के लिए

एक महत्व यहाँ नहीं माना जाना चाहिए (आप अपने कस्टम एल्गोरिथ्म के साथ यह जगह ले सकता है))

BTW XML में एक हस्ताक्षर बिल्डर इस तरह दिखता है:

<?xml version="1.0" encoding="UTF-8"?> 
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#" Id="idPackageSignature"> 
    <SignedInfo> 
    <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> 
    <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/> 
    <Reference Type="http://www.w3.org/2000/09/xmldsig#Object" URI="#idPackageObject"> 
     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
     <DigestValue/> 
    </Reference> 
    <Reference Type="http://www.w3.org/2000/09/xmldsig#Object" URI="#idOfficeObject"> 
     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
     <DigestValue/> 
    </Reference> 
    <Reference Type="http://uri.etsi.org/01903#SignedProperties" URI="#idSignedProperties"> 
     <Transforms> 
     <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> 
     </Transforms> 
     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
     <DigestValue/> 
    </Reference> 
    </SignedInfo> 
    <SignatureValue/> 
    <KeyInfo> 
    <X509Data> 
     <X509Certificate/> 
    </X509Data> 
    </KeyInfo> 
    <Object Id="idPackageObject"> 
    <Manifest> 
     <Reference URI="/_rels/.rels?ContentType=application/vnd.openxmlformats-package.relationships+xml"> 
     <Transforms> 
      <Transform Algorithm="http://schemas.openxmlformats.org/package/2006/RelationshipTransform"> 
      <mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId1"/> 
      </Transform> 
      <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> 
     </Transforms> 
     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
     <DigestValue/> 
     </Reference> 
     <Reference URI="/word/_rels/document.xml.rels?ContentType=application/vnd.openxmlformats-package.relationships+xml"> 
     <Transforms> 
      <Transform Algorithm="http://schemas.openxmlformats.org/package/2006/RelationshipTransform"> 
      <mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId5"/> 
      <mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId4"/> 
      <mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId3"/> 
      <mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId2"/> 
      <mdssi:RelationshipReference xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" SourceId="rId1"/> 
      </Transform> 
      <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> 
     </Transforms> 
     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
     <DigestValue/> 
     </Reference> 
     <Reference URI="/word/document.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"> 
     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
     <DigestValue/> 
     </Reference> 
     <Reference URI="/word/fontTable.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"> 
     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
     <DigestValue/> 
     </Reference> 
     <Reference URI="/word/settings.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"> 
     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
     <DigestValue/> 
     </Reference> 
     <Reference URI="/word/styles.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"> 
     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
     <DigestValue/> 
     </Reference> 
     <Reference URI="/word/theme/theme1.xml?ContentType=application/vnd.openxmlformats-officedocument.theme+xml"> 
     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
     <DigestValue/> 
     </Reference> 
     <Reference URI="/word/webSettings.xml?ContentType=application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"> 
     <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
     <DigestValue/> 
     </Reference> 
    </Manifest> 
    <SignatureProperties> 
     <SignatureProperty Id="idSignatureTime" Target="#idPackageSignature"> 
     <mdssi:SignatureTime xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature"> 
      <mdssi:Format>YYYY-MM-DDThh:mm:ssTZD</mdssi:Format> 
      <mdssi:Value>2015-11-22T17:21:28Z</mdssi:Value> 
     </mdssi:SignatureTime> 
     </SignatureProperty> 
    </SignatureProperties> 
    </Object> 
    <Object Id="idOfficeObject"> 
    <SignatureProperties> 
     <SignatureProperty Id="idOfficeV1Details" Target="#idPackageSignature"> 
     <SignatureInfoV1 xmlns="http://schemas.microsoft.com/office/2006/digsig"> 
      <SetupID/> 
      <SignatureText/> 
      <SignatureImage/> 
      <SignatureComments>TEST SIGNING</SignatureComments> 
      <WindowsVersion>10.0</WindowsVersion> 
      <OfficeVersion>15.0</OfficeVersion> 
      <ApplicationVersion>15.0</ApplicationVersion> 
      <Monitors>1</Monitors> 
      <HorizontalResolution>1920</HorizontalResolution> 
      <VerticalResolution>1080</VerticalResolution> 
      <ColorDepth>32</ColorDepth> 
      <SignatureProviderId>{00000000-0000-0000-0000-000000000000}</SignatureProviderId> 
      <SignatureProviderUrl/> 
      <SignatureProviderDetails>9</SignatureProviderDetails> 
      <SignatureType>1</SignatureType> 
     </SignatureInfoV1> 
     </SignatureProperty> 
    </SignatureProperties> 
    </Object> 
    <Object> 
    <xd:QualifyingProperties xmlns:xd="http://uri.etsi.org/01903/v1.3.2#" Target="#idPackageSignature"> 
     <xd:SignedProperties Id="idSignedProperties"> 
     <xd:SignedSignatureProperties> 
      <xd:SigningTime>2015-11-22T17:21:28Z</xd:SigningTime> 
      <xd:SigningCertificate> 
      <xd:Cert> 
       <xd:CertDigest> 
       <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> 
       <DigestValue/> 
       </xd:CertDigest> 
       <xd:IssuerSerial> 
       <X509IssuerName>[email protected], CN=ALI-PC, OU=ALI-PC, O=ALI-PC, L=ALI-PC, S=ALI-PC, C=98</X509IssuerName> 
       <X509SerialNumber>1</X509SerialNumber> 
       </xd:IssuerSerial> 
      </xd:Cert> 
      </xd:SigningCertificate> 
      <xd:SignaturePolicyIdentifier> 
      <xd:SignaturePolicyImplied/> 
      </xd:SignaturePolicyIdentifier> 
     </xd:SignedSignatureProperties> 
     <xd:SignedDataObjectProperties> 
      <xd:CommitmentTypeIndication> 
      <xd:CommitmentTypeId> 
       <xd:Identifier>http://uri.etsi.org/01903/v1.2.2#ProofOfOrigin</xd:Identifier> 
       <xd:Description>Created and approved this document</xd:Description> 
      </xd:CommitmentTypeId> 
      <xd:AllSignedDataObjects/> 
      <xd:CommitmentTypeQualifiers> 
       <xd:CommitmentTypeQualifier>TEST SIGNING</xd:CommitmentTypeQualifier> 
      </xd:CommitmentTypeQualifiers> 
      </xd:CommitmentTypeIndication> 
     </xd:SignedDataObjectProperties> 
     </xd:SignedProperties> 
    </xd:QualifyingProperties> 
    </Object> 
</Signature> 
+0

संपादन मोड के लिए बीटीडब्ल्यू धन्यवाद :) – lkn2993

+1

नोट: मैंने एक्सएमएल कोड को दोबारा सुधार दिया है जिसमें कई '<' वर्णों की कमी थी। मुझे नहीं पता कि एसओ संपादक का आर्टिफैक्ट रहा है या नहीं। – collapsar

+0

अच्छी तरह से कहें कि मुझे एक परियोजना को कार्यान्वित करने की आवश्यकता है जैसे: http://www.signfiles.com/signature-library/ – lkn2993

उत्तर

1

आप this project के स्रोत कोड पर एक नज़र हो सकता है , यह एमएस अधिकारी के लिए बुनियादी डिजिटल हस्ताक्षर शामिल है ई दस्तावेज ध्यान दें कि कोड थोड़ा पुराना है लेकिन सिद्धांत समान हैं

+0

अच्छा उदाहरण है, हालांकि यह windowsbase लाइब्रेरी में packagedigitalsignaturemanager क्लास का उपयोग कर रहा है, जिसका मतलब कोई स्रोत कोड नहीं है, और इसलिए मैं इसे अनुकूलित करने में असमर्थ हूं। अब अगर आप मुझे उपरोक्त वर्ग या वैकल्पिक विकल्प के स्रोत कोड भी प्रदान करते हैं तो मुझे लगता है कि यह सही जवाब होगा। – lkn2993

+0

कार्यालय दस्तावेजों में डिजिटल हस्ताक्षर (एक्सएडीईएस) की ओर एक और दिलचस्प परियोजना है [यहां] (https://github.com/Caliper/Xades) (फ्रेंच में, लेकिन स्रोत कोड सी # :) में है) – hampidampi

+0

उत्कृष्ट, भले ही परियोजना अलग हस्ताक्षर के लिए डिज़ाइन किया गया है, मैं अभी भी इसे अपने मूल कार्यक्रम के संदर्भ में उपयोग कर सकता हूं और इसके लिए न्यूनतम हस्ताक्षर तैयार कर सकता हूं (ऐसा लगता है कि Xades वास्तव में अप्रत्यक्ष संदर्भ के बजाय कैननिकल ऑब्जेक्ट को इंगित करता है जो चीजों को आसान बनाता है) मैं जवाब को ऊपर उठाऊंगा अब जब मैं समाप्त करूँगा तो मैं इसे एक उत्तर के रूप में चिह्नित करूंगा (यानी, यदि यह सही है)। – lkn2993