SignedCms.ComputeSignature Method

Definition

Creates a signature and adds the signature to the CMS/PKCS #7 message.

Overloads

ComputeSignature(CmsSigner, Boolean)

Creates a signature using the specified signer and adds the signature to the CMS/PKCS #7 message.

ComputeSignature()

Creates a signature and adds the signature to the CMS/PKCS #7 message.

ComputeSignature(CmsSigner)

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

ComputeSignature(CmsSigner, Boolean)

Creates a signature using the specified signer and adds the signature to the CMS/PKCS #7 message.

public:
 void ComputeSignature(System::Security::Cryptography::Pkcs::CmsSigner ^ signer, bool silent);
public void ComputeSignature (System.Security.Cryptography.Pkcs.CmsSigner signer, bool silent);
member this.ComputeSignature : System.Security.Cryptography.Pkcs.CmsSigner * bool -> unit
Public Sub ComputeSignature (signer As CmsSigner, silent As Boolean)

Parameters

signer
CmsSigner

A CmsSigner object that represents the signer.

silent
Boolean

This parameter is not used.

Exceptions

signer is null.

A cryptographic operation could not be completed.

.NET Framework only: A signing certificate is not specified.

.NET Core only: A signing certificate is not specified.

Remarks

.NET Framework Security

The following permissions are required to display the user interface:

The following permissions are required to access the signature key:

ComputeSignature()

Creates a signature and adds the signature to the CMS/PKCS #7 message.

public:
 void ComputeSignature();
public void ComputeSignature ();
member this.ComputeSignature : unit -> unit
Public Sub ComputeSignature ()

Exceptions

.NET Framework (all versions) and .NET Core 3.0 and later: The recipient certificate is not specified.

.NET Core version 2.2 and earlier: No signer certificate was provided.

Remarks

This method succeeds if SubjectIdentifierType.NoSignature was provided as the signerIdentifierType argument of one of the SignedCms constructor overloads. Otherwise, it throws an exception.

.NET Framework Security

The following permissions are required to access the signature key:

ComputeSignature(CmsSigner)

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

public:
 void ComputeSignature(System::Security::Cryptography::Pkcs::CmsSigner ^ signer);
public void ComputeSignature (System.Security.Cryptography.Pkcs.CmsSigner signer);
member this.ComputeSignature : System.Security.Cryptography.Pkcs.CmsSigner -> unit
Public Sub ComputeSignature (signer As CmsSigner)

Parameters

signer
CmsSigner

A CmsSigner object that represents the signer.

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.

Examples

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 dataToSign byte array holds the data to be signed.
Dim contentInfo As New ContentInfo(dataToSign)

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

' Sign the message.
signedCms.ComputeSignature()

' Encode the message.
Dim myCmsMessage As Byte() = 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.
' The dataToSign byte array holds the data to be signed.
Dim contentInfo As New ContentInfo(dataToSign)

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

' Sign the message.
signedCms.ComputeSignature()

' Encode the message.
Dim myCmsMessage As Byte() = signedCms.Encode()

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

Remarks

.NET Framework Security

The following permissions are required to access the signature key:

Applies to