Signature Sign Function. Sign the digital signature using a private key and password. ABCpdf .NET PDF Library.

ABCpdf .net

 
   

Sign the digital signature using a private key and password.

 

   
Syntax  

[C#]
void Sign(string path, string password)
void Sign(byte[] data, string password)
void Sign(Stream stream, string password)
void Sign(X509Certificate2 cert, bool silent)

[Visual Basic]
Sub Sign(path As String, password As String)
Sub Sign(data() As Byte, password As String)
Sub Sign(stream As Stream, password As String)
Sub Sign(cert As X509Certificate2, silent As Boolean)

Throws Exceptions may throw Exception()

 

   

Params
 
Name Description
path The path to the PFX/PKCS #12 (.pfx or .p12) file used for signing.
data

The data for the PFX/PKCS #12 (.pfx or .p12) file used for signing.

stream

The stream for the PFX/PKCS #12 (.pfx or .p12) file used for signing.

password The password used to authorize use of the private key.
cert

The System.Security.Cryptography.X509Certificates.X509Certificate2 object for the PFX/PKCS #12 (.pfx or .p12) certificate used for signing.

silent

Whether to suppress prompting the user to use the private key. While using the private keys of some certificates (such as those imported with the check box "Enable strong private key protected. You will be prompted every time the private key is used by an application if you enable this option." checked), a dialog box is displayed and must be closed if this parameter is false, and the signing fails if this parameter is true. For a non-interactive/unattended operation, this parameter should be set to true.

 

   

Notes
 

Use this method to sign a signature field.

In order to sign a signature, you need to use your private key. To authorize the use of this key, you need to provide your password if you are not using a X509Certificate2 certificate.

Typically, this password protected private key is held in an PFX/PKCS #12 (.pfx or .p12) file. So to perform the signing operation, you provide a path to this file and a password to allow use of the private key.

Time-stamped signatures can be produced by using the service of a Time Stamping Authority (TSA). See TimestampServiceUrl.

If you are signing multiple signature fields in the same PDF document, you should call Commit manually after each signing operation.

If the file is not available, if the file is invalid or if the password is incorrect, then this function will throw an exception.

 

   

Example
 

Read a document and sign a signature field embedded within that document. Before signing, we specify a location and a reason why the document is being digitally signed.

[C#]
Doc theDoc = new Doc();
theDoc.Read(Server.MapPath("../Rez/Authorization.pdf"));
Signature theSig = (Signature)theDoc.Form["Signature"];
theSig.Location = "Washington";
theSig.Reason = "Schedule Agreed";
theSig.Sign(Server.MapPath("../Rez/JohnSmith.pfx"), "1234");
theDoc.Save(Server.MapPath("Signed.pdf"));

[Visual Basic]
Dim theDoc As Doc = New Doc()
theDoc.Read(Server.MapPath("../Rez/Authorization.pdf"))
Dim theSig As Signature = theDoc.Form("Signature")
theSig.Location = "Washington"
theSig.Reason = "Schedule Agreed"
theSig.Sign(Server.MapPath("../Rez/JohnSmith.pfx"), "1234")
theDoc.Save(Server.MapPath("Signed.pdf"))