Click or drag to resize

Pkcs11Signer Class

An IExternalSigner that signs with a key on a PKCS#11 device - a smart card, a USB token or a hardware security module - through the vendor's PKCS#11 library, on Windows, Linux and macOS.
Inheritance Hierarchy
SystemObject
  ExpertPdf.Anywhere.PDFSecurityPkcs11Signer

Namespace: ExpertPdf.Anywhere.PDFSecurity
Assembly: ExpertPdf.Anywhere (in ExpertPdf.Anywhere.dll) Version: 22.0
Syntax
public sealed class Pkcs11Signer : IExternalSigner, 
	IDisposable

The Pkcs11Signer type exposes the following members.

Constructors
 NameDescription
Public methodPkcs11Signer(String, String, String, String) Opens the token and finds the signing key and its certificate.
Public methodPkcs11Signer(String, String, String, String, IListByte) Opens the token and finds the signing key, signing with the certificates given.
Top
Properties
 NameDescription
Public propertyCertificates Gets the signing certificate and its issuers, each DER-encoded.
Top
Methods
 NameDescription
Public methodDispose Closes the session on the token.
Public methodSign Signs the request's digest on the token.
Top
Remarks

The signer opens a session on the token, logs in with the PIN and finds the private key: by its label, or the only signing key on the token when no label is given. The certificate is the token's certificate for that key, unless the certificates are given; the issuer certificates are added from the token and the system stores.

The session stays open until the signer is disposed. Signing happens when the document is saved, so dispose of the signer after the save. Several signers can use the same library at once.

Example
using (Pkcs11Signer signer = new Pkcs11Signer("/usr/lib/softhsm/libsofthsm2.so", "1234", null, null))
{
    PdfSecurityManager manager = new PdfSecurityManager();
    manager.Sign("input.pdf", "signed.pdf", signer, "Signature1", "Approved", "Office", "",
        0, new RectangleF(40, 40, 220, 70), null);
}
See Also