SignedCms.ComputeSignature Method (CmsSigner)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

The ComputeSignature(CmsSigner) method creates a signature using the specified signer and adds the signature to the CMS/PKCS #7 message.

Namespace:   System.Security.Cryptography.Pkcs
Assembly:  System.Security (in System.Security.dll)

public void ComputeSignature(
	CmsSigner signer
)

Parameters

signer
Type: System.Security.Cryptography.Pkcs.CmsSigner

A CmsSigner object that represents the signer.

Exception Condition
ArgumentNullException

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

CryptographicException

A cryptographic operation could not be completed.

The following permissions are required to access the signature key:

The following example shows the steps to compute a signature on a SignedCms message with message content that is not detached. In this case, the message content is included in the SignedCms message.

// The dataToSign byte array holds the data to be signed.
ContentInfo contentInfo = new ContentInfo(dataToSign);

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

// Sign the message.
signedCms.ComputeSignature();

// Encode the message.
byte[] myCmsMessage = signedCms.Encode();

// The signed CMS/PKCS #7 message is ready to send.
// The original content is included in this byte array.

The following example shows the steps to compute a signature on a SignedCms message with message content that is detached. In this case, the message content must be verified independently of the SignedCms message.

// The dataToSign byte array holds the data to be signed.
ContentInfo contentInfo = new ContentInfo(dataToSign);

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

// Sign the message.
signedCms.ComputeSignature();

// Encode the message.
byte[] myCmsMessage = signedCms.Encode();

// The signed CMS/PKCS #7 message is ready to send.
// The original content is not included in this byte array.

.NET Framework
Available since 2.0
Return to top
Show: