共用方式為


使用數字簽名

Microsoft.Office.InfoPath 命名空間的物件模型提供了以程式設計方式使用數位簽章的功能。

數位簽章功能

InfoPath 所提供的數位簽章功能可讓您:

  • 針對整個表單啟用簽章,或是針對表單中可個別簽署的特定資料集啟用簽章。

  • 對於可簽署的每一組資料指定是允許單一簽章還是多個簽章,以及它們之間的關係。 例如,您可以指定它們是否與連署平行,或是每一個新簽章是否副署所有之前的簽章。

  • 指定當表單使用者簽署表單時,對他們顯示的訊息。

  • 插入及查看文件中的簽章。

  • View verifiable non-repudiation information that has been added to each signature for increased security. This additional information, which includes a view of the form as it was presented to each signer, is part of the signature and cannot be removed without invalidating the signature. At any time, you can recall this data by clicking on the signature in the form to display the Verify Digital Signature dialog box.

  • 利用物件模型來處理數位簽章。 透過數位簽章物件模型,在完全信任的表單中新增自訂資訊至簽章區塊。

數位簽章物件模型的概觀

簽署事件

數位簽章的物件模型會提供下列事件。

名稱 描述
Sign
在選取要簽署的資料集之後發生。 您可以使用這個事件處理儲存在數位簽章中的資料。 例如,您可以從信任的時間戳記伺服器新增資料,或是新增異動的伺服器端連署。 如果目前的使用者不是特定群組的成員,您也可以使用這個事件來封鎖簽章。

SignEventArgs 物件

Sign 事件的事件處理常式可搭配提供下列屬性的 SignEventArgs 事件物件一起運作。

名稱 描述
SignedDataBlock
取得引發 Sign 事件的數據集。
SignatureWizard
取得或設定是否要顯示 [數位簽章] 對話方塊。

注意事項

[!注意事項] 在 InfoPath 2003 隨附的 Microsoft.Office.Interop.InfoPath.SemiTrust Managed 程式碼物件模型中, OnSign 事件的 SignEvent 事件物件會提供 XDocument 屬性,以存取此事件相關表單的 XDocument 物件。 但是在 InfoPath Forms Services 或 InfoPath 中,使用 Microsoft.Office.InfoPath 物件模型所建立的表單範本就不必這麼做,因為 XmlForm 類別的物件模型成員可以在表單程式碼中使用 this (C#) 或 Me (Visual Basic) 關鍵字來存取。 例如,若要存取 XmlForm 類別的 Signed 屬性來判斷表單是否已簽署,您可以輸入 this.SignedMe.Signed.

集合和物件

數位簽章的物件模型會提供下列集合。

名稱 描述
SignedDataBlockCollection
表單範本中 SignedDataBlock 物件的集合,如 InfoPath 設計模式中的設計時間所定義。 SignedDataBlockCollection 集合會實作可用來存取與窗體相關聯之 SignedDataBlock 對象的屬性。 與窗體相關聯的 SignedDataBlockCollection 物件可透過 XmlForm 類別的 SignedDataBlocks 屬性存取。
SignatureCollection
包含表單中每個 SignedDataBlock 物件的 Signature 物件集合。 SignatureCollection 類別會實作屬性和方法,可用來存取窗體的關聯 Signature 物件,以及建立簽章。 使用 Signatures 屬性可以存取與 SignedDataBlock 相關聯的 SignatureCollection 物件。 當您使用 SignatureCollection 類別的 CreateSignature 方法時,請記住,在 Signature 物件上呼叫 Sign 方法之前,不會寫入簽章。 您只能從完全信任之表單範本的 Sign 事件處理常式來呼叫這些方法。

數位簽章的物件模型會提供下列物件。

名稱 描述
SignedDataBlock
代表表單中可簽署的資料集。 SignedDataBlock 物件提供許多屬性和一個方法,可用來以程式設計方式與可簽署的資料集互動。
簽章
代表已新增至表單或表單中可簽署資料集的數位簽章。 Signature 物件會實作可用來擷取數位簽名相關信息的屬性,以及用來撰寫 XML 數位簽名區塊並計算其密碼編譯哈希值的 Sign 方法。
認證
代表已用來建立簽章的 X.509 數位憑證。

以程式設計方式使用數位簽章

Microsoft.Office.InfoPath 命名空間的物件模型提供了可用來以程式設計方式與數位簽章互動的成員。 特別是,完全信任的表單可以根據以下時刻表,將自訂資訊加入到簽章區塊中,然後再認可這些資訊:

  1. 使用者選擇將數位簽章加入至表單。

  2. 會顯示 [數位簽章] 對話方塊,然後使用者按一下 [新增],並選取要簽署的資料。

  3. 會引發 SignedDataBlock 物件所代表之選定資料的 Sign 事件,並執行 SignedDataBlock 物件的 Sign() 方法和 SignatureCollection 集合的 CreateSignature 方法。

  4. 會執行任何選用的自訂動作。

  5. 會執行 Signature 物件的 Sign() 方法。

  6. 顯示 [簽署] 對話方塊供您輸入名稱 (或選取簽章圖像)、選取簽署所用的憑證及輸入註解。

  7. 在按一下 [簽署] 按鈕時,會將該簽章加入到表單的簽章集合中,而且會擷取不可否認性資訊,並與此簽章一起儲存 (之後可以使用以下方式來檢視:按一下 [數位簽章] 對話方塊上的 [檢視簽署的表單],然後按一下 [請參閱已收集的其他簽署資訊])。

下列範例會在使用者簽署選定資料,以及使用從信任之時間戳記服務所擷取的時間戳記值來副署簽章時,叫用 Sign() 方法。

public void FormEvents_Sign(object sender, SignEventArgs e)
{
   // Add a new Signature object to the SignedDataBlockCollection.
   Signature thisSignature = 
      e.SignedDataBlock.Signatures.CreateSignature();
   // Write the XML digital signature block and compute hash
   // for signed data.
   thisSignature.Sign();
   // Countersign the signature with a trusted timestamp.
   // Get the XML node storing the signature block.
   XPathNavigator oNodeSig = thisSignature.SignatureBlockXmlNode;
   XPathNavigator oNodeSigValue = 
      oNodeSig.SelectSingleNode(
      ".//*[local-name(.)='signatureValue']");
   // Get timestamp from a trusted timestamp service (fictitious).
   MyTrustedTimeStampService s = new MyTrustedTimeStampService();
   string strVerifiedTimeStamp = s.AddTimeStamp(oNodeSigValue.Value);
   // Add the value returned from the timestamp service to the 
   // unsigned part of the signature block.
   XPathNavigator oNodeObj = 
      oNodeSig.SelectSingleNode(".//*[local-name(.)='Object']");
   XPathNavigator oNode = oNodeObj.Clone();
   oNode.SetValue(strVerifiedTimeStamp);
   oNodeObj.MoveToParent();
   oNodeObj.AppendChild(oNode);
   e.SignatureWizard = false;
}
Public Sub FormEvents_Sign(ByVal sender As Object, _
   ByVal e As SignEventArgs)
   ' Add a new Signature object to the SignedDataBlockCollection.
   Dim thisSignature As Signature = 
      e.SignedDataBlock.Signatures.CreateSignature
   ' Write the XML digital signature block and compute hash
   ' for signed data.
   thisSignature.Sign()
   ' Countersign the signature with a trusted timestamp.
   ' Get the XML node storing the signature block
   Dim oNodeSig As XPathNavigator  = _
      thisSignature.SignatureBlockXmlNode
   Dim oNodeSigValue As XPathNavigator  = _
      oNodeSig.SelectSingleNode(_
      ".//*[local-name(.)='signatureValue']")
   ' Get timestamp from a trusted timestamp service (fictitious).
   Dim s As MyTrustedTimeStampService = New MyTrustedTimeStampService()
   Dim strVerifiedTimeStamp As String  = _
      s.AddTimeStamp(oNodeSigValue.Value)
   ' Add the value returned from the timestamp service to the 
   ' unsigned part of the signature block.
   Dim oNodeObj As XPathNavigator  = 
      oNodeSig.SelectSingleNode(".//*[local-name(.)='Object']")
   Dim oNode As XPathNavigator  = oNodeObj.Clone()
   oNode.SetValue(strVerifiedTimeStamp)
   oNodeObj.MoveToParent()
   oNodeObj.AppendChild(oNode)
   e.SignatureWizard = False