Signature 对象

         
SignatureSet
Signature

对应于附加到文档的数字签名。Signature 对象包含于 Document 对象的 SignatureSet 集合之中。

使用 Signature 对象

可以使用 Add 方法向 SignatureSet 集合添加 Signature 对象,并使用 Item 方法返回已有成员。要从 SignatureSet 集合中删除一个 Signature 对象,请使用 Signature 对象的 Delete 方法。

本示例提示用户选择 Microsoft Word 中活动文档的数字签名。要使用本示例,请在 Word 中打开文档,并向该函数传递与“数码证书”对话框中数码证书的“颁发者”和“颁发给”字段相符的证书颁发者名字和证书签署者名字。该函数在将新签名提交到磁盘之前将进行测试以确保用户所选择的数字签名满足指定条件,例如没有过期。

Function AddSignature(ByVal strIssuer As String, _
    strSigner As String) As Boolean

    On Error GoTo Error_Handler

    Dim sig As Signature

    'Display the dialog box that lets the
    'user select a digital signature.
    'If the user selects a signature, then
    'it is added to the Signatures
    'collection. If the user doesn't, then
    'an error is returned.
    Set sig = ActiveDocument.Signatures.Add

    'Test several properties before commiting the Signature object to disk.
    If sig.Issuer = strIssuer And _
        sig.Signer = strSigner And _
        sig.IsCertificateExpired = False And _
        sig.IsCertificateRevoked = False And _
        sig.IsValid = True Then

        MsgBox "Signed"
        AddSignature = True
    'Otherwise, remove the Signature object from the SignatureSet collection.
    Else
        sig.Delete
        MsgBox "Not signed"
        AddSignature = False
    End If

    'Commit all signatures in the SignatureSet collection to the disk.
    ActiveDocument.Signatures.Commit

    Exit Function
Error_Handler:
    AddSignature = False
    MsgBox "Action cancelled."
End Function