Can't create a signed PDF (PAdES)

Hi,

I am trying to add an electronic signature to a PDF document.
I generated the certificate with CyptoDemo (64-bit) “Generate Certificate” using the following settings:

  • Signature algorithm: RSASA v1.5

  • Hash function: SHA256

  • Key length: 256

    Key and crt files are generated.

    To sign the PDF, I go to ‘Generate adES’ with the following parameters:

    • Signature format : PAdES

    The generation crashes:

    • File : PAdESObj.pas :
      ** function TPAdES.ComputeSize(s: string; n: string): string;
      ..
      while (J <= K) and (TryStrToInt(Result[J], I) = true) do
      Inc(J);
      ..

error : 'Le projet CryptoDemo.exe a déclenché la classe d'exception ERangeError avec le message 'Erreur de vérification d'étendue'.'

  • then
    ** function TPAdES.FirstPart(ts: TStringList): string;
    ..
    while (i > 0) and (FNumberObj[i] <> ' ') do begin
    temp := FNumberObj[i] + temp;
    i := i - 1;
    end;

error : 'Le projet CryptoDemo.exe a déclenché la classe d'exception ERangeError avec le message 'Erreur de vérification d'étendue'.'

next

  • file : CAdESObj.pas
    ** function TCAdES.GenerateSignerInfos(InStream: TStream; AdditionalData: string): string;
    ..
    Signature := GenerateSignatureValue(signedAttrs);
    ..

error : 'Le projet CryptoDemo.exe a déclenché la classe d'exception ECryptoPack avec le message 'Modulus length incorrect, must be 512'.'

For the first two errors, I bypassed the problem with a "TRY .. EXCEPT END"

What should I do?

NB
Note: this issue also occurred with version 4, but only with the first two errors (which I had bypassed).

Hi Olivier,

Hard to say without more details. I would need the PDF document, the certificate and the ky( with the password).

But you can try TMS Signer (on TMS web site, freeware) first.

Else bernard [at] tmssoftware [dot] com

Regards,

bernard

Hi,

I had prepared all these files, but I forget …

Test.zip (35.0 KB)

about TMS Signer, the link https://www.cyberens.fr/wp-content/uploads/2025/07/TMSSigner.zip is not anymore available, and I didn’t find it in your “Freeware” I found “AdesDocumentSignature”.

I tested with it and I receive this message : Hash fonction not supported.

I guess, my parameters to generate the certificate are incorrects; which ones should I use

TMS Signer is also at https://www.cyberens.fr/wp-content/uploads/2026/01/TMSSigner.zip

OK, quick fix, in AdESObj.pas, and in procedure TAdES.RSAExtractPrivateKey:

// Sequence is:
//  modulus, public exponent, private exponent, prime1, prime2
//  exponent1, exponent2, coefficient
RSA.inputFormat     := raw; // <=================== ADD THIS
RSA.outputFormat    := hexa;
RSA.modulus         := ASN.RSAKeySet.modulus;

Note that if the certificate is not in the Windows Store, Acrobat will not validate the signature.

It works

GREAT :clap: :+1:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.