EldoS | Feel safer!

Software components for data protection, secure storage and transfer

signing Multiple PDF docs

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#27425
Posted: 11/27/2013 03:10:06
by Ken Ivanov (EldoS Corp.)

To answer your second question, there's a TinySignerPKCS11 sample in your Documents\EldoS\SecureBlackbox.NET\Samples\C#\PDFBlackbox\Desktop\ folder which illustrates the use of PKCS#11 API for signing PDF documents.
#27427
Posted: 11/27/2013 03:17:25
by Bilal SEZER (Basic support level)
Joined: 11/26/2013
Posts: 15

That is my code, yes I use TElWinCertStorage.

Code
  F := TFileStream.Create(TempPath, fmOpenReadWrite or fmShareDenyWrite);
  try
    try
      Document.Open(F);
      try

        if Document.Encrypted then
        begin
          MessageDlg(' !!!', mtError, [mbOk], 0);
          Exit;
        end;

        ELX509Cert.KeyMaterial.SignaturePIN := 'XXXX';

        Index := Document.AddSignature;
        Sig := Document.Signatures[Index];
        Sig.Handler :=  PublicKeyHandler;


        Sig.SigningTime := LocalTimeToUTCTime(Now);

        Sig.SignatureType := stDocument;
        Sig.Invisible := False;
          begin
            SimpleFont := TElPDFSimpleFont.Create;
            SimpleFont.BaseFont := 'Helvetica';
            Sig.WidgetProps.AddFont(SimpleFont);
          end;

        CertStorage.Clear;
        PublicKeyHandler.SignatureType := pstPKCS7SHA1;
        begin
          Cert := WinCertStorage.Certificates[CertId];
          CertStorage.Add(Cert);
     PublicKeyHandler.SignatureType := pstPKCS7SHA1;
        end;
        PublicKeyHandler.CertStorage := CertStorage;
        PublicKeyHandler.CustomName := 'Adobe.PPKMS';

        Success := true;
      finally
        Document.Close(Success);
      end;
    finally
      FreeAndNil(F);
    end;
  except
    on E : Exception do
    begin
      MessageDlg('Error: ' + E.Message, mtError, [mbOk], 0);
      Success := false;
    end;
  end;
#27429
Posted: 11/27/2013 03:25:24
by Ken Ivanov (EldoS Corp.)

Thanks.

The unavailability of the KeyMaterial object indicates that the certificate carries a public key of unsupported format or algorithm. Is your certificate supposed to be a standard RSA one?
#27432
Posted: 11/27/2013 03:53:09
by Bilal SEZER (Basic support level)
Joined: 11/26/2013
Posts: 15

Public Key looks like RSA (2048 bits). How can I be sure that my certificate is standard RSA.


#27441
Posted: 11/27/2013 04:59:32
by Ken Ivanov (EldoS Corp.)

Bilal,

Thank you, indeed it looks like a valid RSA certificate.

Could you please do the following small check for us: please try to open your certificate with the CertDemo sample (Documents\EldoS\SecureBlackbox.NET\Samples\C#\PKIBlackbox\Desktop\CertDemo), which is capable of accessing Windows system certificate stores, and check if it displays the public key in the certificate details list. This will let us know if the issue is somehow related to your environment or to the code used to get the certificate.


#27443
Posted: 11/27/2013 06:27:18
by Bilal SEZER (Basic support level)
Joined: 11/26/2013
Posts: 15

I checked.


#27444
Posted: 11/27/2013 06:33:57
by Ken Ivanov (EldoS Corp.)

Thank you. This means that the key is actually loaded, and the private key is also available for this certificate. Please compare your code with the code of the sample to find out why the certificate is not loaded for you in your code.
#27447
Posted: 11/27/2013 07:28:35
by Bilal SEZER (Basic support level)
Joined: 11/26/2013
Posts: 15

Which sample exactly do you mean?
#27448
Posted: 11/27/2013 07:35:10
by Ken Ivanov (EldoS Corp.)

The CertDemo one, - the piece that loads certificates from the Windows system stores, to be exact.
#27592
Posted: 12/06/2013 07:26:33
by Bilal SEZER (Basic support level)
Joined: 11/26/2013
Posts: 15

Hi,

I tried

Cert.KeyMaterial.SignaturePIN := 'XXXX';
Cert.KeyMaterial.KeyExchangePIN := 'XXXX';

and it works for the first PDF signature but it keeps asking PIN for subsequent PDF files.
Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.

Reply

Statistics

Topic viewed 1858 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!