Type Default Value Read Only Description

[Visual Basic]
null No A delegate called to perform custom signing of the PDF.




A delegate called to perform a custom signing of the PDF content digest and signed attributes.

The definition of the SigningDelegate delegate is as follows.

delegate byte[] SigningDelegate(byte[] data);;

[Visual Basic]
Delegate Function SigningDelegate(data As Byte()) As Byte();

The function is provided an ASN.1 encoded byte array containing the digest of the PDF content.

It should return a signed encoded CMS - an ASN.1 encoded object containing the signature.




The following example shows how an external delegate might be used.

public void SignDoc() {
  // Just use public certificate from file - i.e. do not obtain from registry
  string certPath = TestEnv.GetRezPath(@"C:\GlobalSign.cer");
  string outfile = TestEnv.GetTestPath("Test2994_TestExternalSigningDelegate.pdf");
  using (Doc doc = new Doc()) {
    Signature sig = (Signature)doc.Form.Fields["Signature1"];
    sig.CustomSigner = ExternalSigner;
    sig.Reason = "Test External Signing";
    X509Certificate2 cert = new X509Certificate2(@"C:\GlobalSign.cer");
    sig.Sign(cert, true, new Oid(CryptoConfig.MapNameToOID("SHA512")), X509IncludeOption.EndCertOnly);

byte[] ExternalSigner(byte[] data) {
  string serial = "10 20 30 10 40 10 40 50 60 10 20 30"; // needs value
  SecureString password = new SecureString(); // needs value
  X509Certificate2 cert = null;
  X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
  try {
    store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly | OpenFlags.MaxAllowed);
    cert = store.Certificates.Find(X509FindType.FindBySerialNumber, serial, false)[0];
  finally {
  if (cert.PrivateKey is RSACryptoServiceProvider == false)
    throw new Exception("Unsupported key type.");
  RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)cert.PrivateKey;
  CspParameters cspParams = new CspParameters(1, rsa.CspKeyContainerInfo.ProviderName,
    rsa.CspKeyContainerInfo.UniqueKeyContainerName) {
    KeyPassword = password,
    Flags = CspProviderFlags.NoPrompt
  RSACryptoServiceProvider service = new RSACryptoServiceProvider(cspParams);
  return service.SignData(data, "2.16.840.");

[Visual Basic]
Public Sub SignDoc()
  Dim certPath As String = TestEnv.GetRezPath("C:\GlobalSign.cer")
  Dim outfile As String = TestEnv.GetTestPath("Test2994_TestExternalSigningDelegate.pdf")
  Using doc As Doc = New Doc()
    Dim sig As Signature = CType(doc.Form.Fields("Signature1"), Signature)
    sig.CustomSigner = AddressOf ExternalSigner
    sig.Reason = "Test External Signing"
    Dim cert As X509Certificate2 = New X509Certificate2("C:\GlobalSign.cer")
    sig.Sign(cert, True, New Oid(CryptoConfig.MapNameToOID("SHA512")), X509IncludeOption.EndCertOnly)
  End Using
End Sub

Private Function ExternalSigner(ByVal data As Byte()) As Byte()
  Dim serial As String = "10 20 30 10 40 10 40 50 60 10 20 30"
  Dim password As SecureString = New SecureString()
  Dim cert As X509Certificate2 = Nothing
  Dim store As X509Store = New X509Store(StoreName.My, StoreLocation.CurrentUser)
    store.Open(OpenFlags.[ReadOnly] Or OpenFlags.OpenExistingOnly Or OpenFlags.MaxAllowed)
    cert = store.Certificates.Find(X509FindType.FindBySerialNumber, serial, False)(0)
  End Try
  If TypeOf cert.PrivateKey Is RSACryptoServiceProvider = False Then Throw New Exception("Unsupported key type.")
  Dim rsa As RSACryptoServiceProvider = CType(cert.PrivateKey, RSACryptoServiceProvider)
  Dim cspParams As CspParameters = New CspParameters(1, rsa.CspKeyContainerInfo.ProviderName, rsa.CspKeyContainerInfo.UniqueKeyContainerName)
  capParamss.KeyPassword = password,
  capParamss.Flags = CspProviderFlags.NoPrompt
  Dim service As RSACryptoServiceProvider = New RSACryptoServiceProvider(cspParams)
  Return service.SignData(data, "2.16.840.")
End Function