SignedCms.ComputeSignature 方法

定義

建立簽章,並將簽章新增至 CMS/PKCS #7 訊息。

多載

ComputeSignature(CmsSigner, Boolean)

使用指定的簽署人建立簽章,並將簽章加入至 CMS/PKCS #7 訊息。

ComputeSignature()

建立簽章,並將簽章新增至 CMS/PKCS #7 訊息。

ComputeSignature(CmsSigner)

使用指定的簽署人建立簽章,並將簽章加入至 CMS/PKCS #7 訊息。

ComputeSignature(CmsSigner, Boolean)

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

使用指定的簽署人建立簽章,並將簽章加入至 CMS/PKCS #7 訊息。

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)

參數

signer
CmsSigner

CmsSigner 物件,代表簽署人。

silent
Boolean

僅限 .NET Core 和 .NET 5+: true 若要要求停用 PIN 提示的開啟密鑰,如果支援,則為 ,否則為 false。 在 .NET Framework 中,不會使用此參數,而且一律會顯示 PIN 提示 (如有需要)。

例外狀況

signernull

密碼編譯作業無法完成。

僅限 .NET Framework:未指定簽署憑證。

僅限 .NET Core 和 .NET 5+:未指定簽署憑證。

備註

僅限 .NET Core:如果CmsSigner.PrivateKey值不是 Null,參數silent就不會有任何作用。 所提供的值可控制簽章是否顯示 PIN 提示。 PrivateKey即使 屬性為 Null 且 silent 參數設定為 true,某些作業系統和簽署者選項的組合仍會導致 PIN 提示。

需要下列許可權,才能在 .NET Framework 上顯示使用者介面:

需要下列許可權才能存取 .NET Framework 上的簽章金鑰:

適用於

ComputeSignature()

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

建立簽章,並將簽章新增至 CMS/PKCS #7 訊息。

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

例外狀況

.NET Framework (所有版本) 以及 .NET Core 3.0 和更新版本:未指定收件者憑證。

.NET Core 2.2 版和更舊版本:未提供簽署人憑證。

備註

如果SubjectIdentifierType.NoSignature提供做為其中SignedCms一個建構函式多載的自變數,signerIdentifierType這個方法就會成功。 否則,會擲回例外狀況。

需要下列許可權才能存取 .NET Framework 上的簽章金鑰:

適用於

ComputeSignature(CmsSigner)

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

使用指定的簽署人建立簽章,並將簽章加入至 CMS/PKCS #7 訊息。

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)

參數

signer
CmsSigner

CmsSigner 物件,代表簽署人。

例外狀況

Null 參考已傳遞至不接受它做為有效引數的方法。

密碼編譯作業無法完成。

範例

下列範例顯示使用未中斷連結之訊息內容之訊息上 SignedCms 計算簽章的步驟。 在此情況下,訊息內容會包含在訊息中 SignedCms

// 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.

下列範例顯示使用已中斷連結之訊息內容之訊息上 SignedCms 計算簽章的步驟。 在此情況下,訊息內容必須與訊息無關 SignedCms 進行驗證。

// 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.

備註

需要下列許可權才能存取 .NET Framework 上的簽章金鑰:

適用於