IPdf | |
The IPdfExternalSigner type exposes the following members.
| Name | Description | |
|---|---|---|
| Certificates | Gets the certificates of the signer, each DER-encoded: the signing certificate first, then the certificates of its issuers. |
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.
// 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");