Click or drag to resize
Pdf Library for .NET

IPdfExternalSigner Interface

Signs a PDF document with a private key held outside the library - in a hardware security module (HSM), a smart card, a PKCS#11 token or a cloud key service.

Namespace: SelectPdf.Universal
Assembly: SelectPdf.Universal (in SelectPdf.Universal.dll) Version: 26.5
Syntax
public interface IPdfExternalSigner

The IPdfExternalSigner type exposes the following members.

Properties
 NameDescription
Public propertyCertificates Gets the certificates of the signer, each DER-encoded: the signing certificate first, then the certificates of its issuers.
Top
Methods
 NameDescription
Public methodSign Signs the request with the private key of the signing certificate.
Top
Remarks

The library builds the whole signature - the certificates, the signed attributes, the timestamp and the long-term validation data - and asks the signer for one thing only: the raw signature value over Data. The private key never has to leave the device or service that holds it.

Pass an implementation to Sign(IPdfExternalSigner) or to a PdfDigitalSignatureElement. When the signature cannot be produced while the document is being saved - a remote signing service where the signer approves on another device - use PrepareExternalSignature(IListByte, String) and CompleteExternalSignature(String, String, String, IListByte, PdfSignatureDigest, Byte) instead.

Example
// A signer backed by any key that can sign a digest:
// an HSM, a smart card, a key service.
class KeyServiceSigner : IPdfExternalSigner
{
    private readonly System.Security.Cryptography.RSA key;
    public KeyServiceSigner(IList<byte[]> certificates,
        System.Security.Cryptography.RSA key)
    {
        Certificates = certificates;
        this.key = key;
    }

    public IList<byte[]> Certificates { get; }

    public byte[] Sign(PdfExternalSigningRequest request)
    {
        var hash = new System.Security.Cryptography.HashAlgorithmName(
            request.DigestAlgorithm.ToString());
        return key.SignHash(request.Digest, hash,
            System.Security.Cryptography.RSASignaturePadding.Pkcs1);
    }
}

PdfSecurityManager manager = new PdfSecurityManager();
manager.Load("contract.pdf");
manager.Sign(new KeyServiceSigner(certificates, key), "Signature1");
manager.Save("contract-signed.pdf");
See Also