SignedCms.CheckSignature Method

Definition

Verifies the digital signatures on the signed CMS/PKCS #7 message.

Overloads

CheckSignature(Boolean)

The CheckSignature(Boolean) method verifies the digital signatures on the signed CMS/PKCS #7 message and, optionally, validates the signers' certificates.

CheckSignature(X509Certificate2Collection, Boolean)

The CheckSignature(X509Certificate2Collection, Boolean) method verifies the digital signatures on the signed CMS/PKCS #7 message by using the specified collection of certificates and, optionally, validates the signers' certificates.

CheckSignature(Boolean)

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

The CheckSignature(Boolean) method verifies the digital signatures on the signed CMS/PKCS #7 message and, optionally, validates the signers' certificates.

C#
public void CheckSignature(bool verifySignatureOnly);

Parameters

verifySignatureOnly
Boolean

A Boolean value that specifies whether only the digital signatures are verified without the signers' certificates being validated.

If verifySignatureOnly is true, only the digital signatures are verified. If it is false, the digital signatures are verified, the signers' certificates are validated, and the purposes of the certificates are validated. The purposes of a certificate are considered valid if the certificate has no key usage or if the key usage supports digital signatures or nonrepudiation.

Exceptions

A null reference was passed to a method that does not accept it as a valid argument.

A cryptographic operation could not be completed.

A method call was invalid for the object's current state.

Examples

The following example shows the placement of CheckSignature(Boolean) among the steps necessary to verify the signatures on a SignedCms message. In this example, the message content is not detached. The message content is included in the SignedCms message.

C#
// 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);

The following example shows the placement of CheckSignature(Boolean) among the steps necessary to verify the signatures on a SignedCms message. In this example, the message content is detached, so the message content must verified independently of the SignedCms message.

C#
// 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);

Remarks

This method verifies all signatures, including countersignatures, on the CMS/PKCS #7 message. If there are signed attributes included with the message, these attributes are also verified. If the option is chosen to validate certificates, the entire included portion of the certificate chain is validated.

This method throws an exception if the verification of a digital signature fails or any validation requirements are not met.

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

CheckSignature(X509Certificate2Collection, Boolean)

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

The CheckSignature(X509Certificate2Collection, Boolean) method verifies the digital signatures on the signed CMS/PKCS #7 message by using the specified collection of certificates and, optionally, validates the signers' certificates.

C#
public void CheckSignature(System.Security.Cryptography.X509Certificates.X509Certificate2Collection extraStore, bool verifySignatureOnly);

Parameters

extraStore
X509Certificate2Collection

An X509Certificate2Collection object that can be used to validate the certificate chain. If no additional certificates are to be used to validate the certificate chain, use CheckSignature(Boolean) instead of CheckSignature(X509Certificate2Collection, Boolean).

verifySignatureOnly
Boolean

A Boolean value that specifies whether only the digital signatures are verified without the signers' certificates being validated.

If verifySignatureOnly is true, only the digital signatures are verified. If it is false, the digital signatures are verified, the signers' certificates are validated, and the purposes of the certificates are validated. The purposes of a certificate are considered valid if the certificate has no key usage or if the key usage supports digital signatures or nonrepudiation.

Exceptions

A null reference was passed to a method that does not accept it as a valid argument.

A cryptographic operation could not be completed.

A method call was invalid for the object's current state.

Remarks

This method verifies all signatures, including countersignatures, on the CMS/PKCS #7 message. If there are signed attributes included with the message, these attributes are also verified. If the option is chosen to validate certificates, the entire included portion of the certificate chain is validated.

This method throws an exception if the verification of a digital signature fails or any validation requirements are not met.

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9