Edit

Share via


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)

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

ComputeSignature(CmsSigner, Boolean)

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

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

.NET Core and .NET 5+ only: true to request opening keys with PIN prompts disabled, where supported; otherwise, false. In .NET Framework, this parameter is not used and a PIN prompt is always shown, if required.

Exceptions

signer is null.

A cryptographic operation could not be completed.

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

.NET Core and .NET 5+ only: A signing certificate is not specified.

Remarks

.NET Core only: The silent parameter has no effect if the CmsSigner.PrivateKey value is not null. The provided value controls whether or not computing the signature shows a PIN prompt. Even when the PrivateKey property is null and the silent parameter is set to true, some combinations of operating system and signer options can still result in a PIN prompt.

The following permissions are required to display the user interface on .NET Framework:

The following permissions are required to access the signature key on .NET Framework:

Applies to

ComputeSignature()

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

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.

The following permissions are required to access the signature key on .NET Framework:

Applies to

ComputeSignature(CmsSigner)

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

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

The following permissions are required to access the signature key on .NET Framework:

Applies to