SignedCms.CheckSignature 方法

定义

验证签名 CMS/PKCS #7 消息上的数字签名。

重载

CheckSignature(Boolean)

CheckSignature(Boolean) 方法验证签名 CMS/PKCS #7 消息上的数字签名,并验证签名者的证书(可选)。

CheckSignature(X509Certificate2Collection, Boolean)

CheckSignature(X509Certificate2Collection, Boolean) 方法通过使用指定的证书集合对签名 CMS/PKCS #7 消息的数字签名进行验证,并对签名者的证书进行验证(可选)。

CheckSignature(Boolean)

Source:
SignedCms.cs
Source:
SignedCms.cs
Source:
SignedCms.cs
Source:
SignedCms.cs

CheckSignature(Boolean) 方法验证签名 CMS/PKCS #7 消息上的数字签名,并验证签名者的证书(可选)。

public:
 void CheckSignature(bool verifySignatureOnly);
public void CheckSignature (bool verifySignatureOnly);
member this.CheckSignature : bool -> unit
Public Sub CheckSignature (verifySignatureOnly As Boolean)

参数

verifySignatureOnly
Boolean

一个 Boolean 值,指定是否只验证数字签名而不验证签名者的证书。

如果 verifySignatureOnlytrue,则仅验证数字签名。 如果该值为 false,则验证数字签名、签名者的证书和证书的用途。 如果证书没有密钥用法或如果密钥用法支持数字签名或认可,则认为该证书的用途有效。

例外

向不接受空引用作为有效参数的方法传递了一个空引用。

未能完成加密操作。

一个方法调用对于对象的当前状态无效。

示例

以下示例演示在验证邮件签名SignedCms所需的步骤之间放置 CheckSignature(Boolean) 。 在此示例中,消息内容未分离。 消息内容包含在消息中 SignedCms

// Create a new, nondetached SignedCms message.
SignedCms signedCms = new SignedCms();

// encodedMessage is the encoded message received from
// the sender.
signedCms.Decode(encodedMessage);

// Verify the signature without validating the
// certificate.
signedCms.CheckSignature(true);
' Create a new, nondetached SignedCms message.
Dim signedCms As New SignedCms()

' encodedMessage is the encoded message received from 
' the sender.
signedCms.Decode(encodedMessage)

' Verify the signature without validating the 
' certificate.
signedCms.CheckSignature(True)

以下示例演示在验证邮件签名SignedCms所需的步骤之间放置 CheckSignature(Boolean) 。 在此示例中,消息内容是分离的,因此消息内容必须独立于消息进行 SignedCms 验证。

// Create a ContentInfo object from the inner content obtained
// independently from encodedMessage.
ContentInfo contentInfo = new ContentInfo(innerContent);

// Create a new, detached SignedCms message.
SignedCms signedCms = new SignedCms(contentInfo, true);

// encodedMessage is the encoded message received from
// the sender.
signedCms.Decode(encodedMessage);

// Verify the signature without validating the
// certificate.
signedCms.CheckSignature(true);
' Create a ContentInfo object from the inner content obtained 
' independently from encodedMessage.
Dim contentInfo As New ContentInfo(innerContent)

' Create a new, detached SignedCms message.
Dim signedCms As New SignedCms(contentInfo, True)

' encodedMessage is the encoded message received from 
' the sender.
signedCms.Decode(encodedMessage)

' Verify the signature without validating the 
' certificate.
signedCms.CheckSignature(True)

注解

此方法验证 CMS/PKCS #7 消息上的所有签名,包括反签名。 如果消息中包含有符号属性,则还会验证这些属性。 如果选择选项来验证证书,则会验证证书链的整个包含部分。

如果数字签名的验证失败或不符合任何验证要求,则此方法将引发异常。

适用于

CheckSignature(X509Certificate2Collection, Boolean)

Source:
SignedCms.cs
Source:
SignedCms.cs
Source:
SignedCms.cs
Source:
SignedCms.cs

CheckSignature(X509Certificate2Collection, Boolean) 方法通过使用指定的证书集合对签名 CMS/PKCS #7 消息的数字签名进行验证,并对签名者的证书进行验证(可选)。

public:
 void CheckSignature(System::Security::Cryptography::X509Certificates::X509Certificate2Collection ^ extraStore, bool verifySignatureOnly);
public void CheckSignature (System.Security.Cryptography.X509Certificates.X509Certificate2Collection extraStore, bool verifySignatureOnly);
member this.CheckSignature : System.Security.Cryptography.X509Certificates.X509Certificate2Collection * bool -> unit
Public Sub CheckSignature (extraStore As X509Certificate2Collection, verifySignatureOnly As Boolean)

参数

extraStore
X509Certificate2Collection

可用于验证证书链的 X509Certificate2Collection 对象。 如果没有其他证书要用于验证证书链,则应使用 CheckSignature(Boolean) 而不是 CheckSignature(X509Certificate2Collection, Boolean)

verifySignatureOnly
Boolean

一个 Boolean 值,指定是否只验证数字签名而不验证签名者的证书。

如果 verifySignatureOnlytrue,则仅验证数字签名。 如果该值为 false,则验证数字签名、签名者的证书和证书的用途。 如果证书没有密钥用法或如果密钥用法支持数字签名或认可,则认为该证书的用途有效。

例外

向不接受空引用作为有效参数的方法传递了一个空引用。

未能完成加密操作。

一个方法调用对于对象的当前状态无效。

注解

此方法验证 CMS/PKCS #7 消息上的所有签名,包括反签名。 如果消息中包含有符号属性,则还会验证这些属性。 如果选择选项来验证证书,则会验证证书链的整个包含部分。

如果数字签名的验证失败或不符合任何验证要求,则此方法将引发异常。

适用于