login about faq


i'm trying to sign a PDF file with this code. But "Crypt.SignBytesENC" returns a empty string. can you help me to see the problem? thanks!!

    Dim CertNome As String = ""
    Dim CertSerie As String = ""

    'Prepara o objecto Chilkat
    Dim Crypt As New Chilkat.Crypt2

    'Desbloqueia a função
    Dim Exito As Boolean = Crypt.UnlockComponent("xxxxx")
    If (Exito <> True) Then
        PDF_Assinar = 1
        Exit Function
    End If

    Dim CryptCert As New Chilkat.Cert

    Exito = CryptCert.LoadFromFile(qLocalCert)
    If Exito <> True Then
        PDF_Assinar = 2
        Exit Function
    End If

    CertNome = CryptCert.IssuerDN
    CertSerie = CryptCert.SerialNumber

    Crypt.Charset = "unicode"
    Crypt.EncodingMode = "base64"
    Crypt.CryptAlgorithm = "none"

    Dim qFicheiroPDF_Final As String = Crypt.SignBytesENC(Crypt.ReadFile(qLocal & qFicheiro))

    If Not IsNothing(qFicheiroPDF_Final) = True Then
        Dim GravarPDF As New System.IO.StreamWriter(qLocal & qFicheiro.Replace("_TEMP", ""))

        PDF_Assinar = 3
    End If
Catch ex As Exception
    PDF_Assinar = 99 'Indeterminado
End Try

asked Mar 25 '15 at 06:49

Eduardo%20Pereira's gravatar image

Eduardo Pereira

I'd try separating the ReadFile call from the SignBytesEnc call to make sure that it is actually returning data.

Next, please post the contents of the LastErrorText property immediately after the first failing call (whether ReadFile or SignBytesEnc are failing).


answered Mar 25 '15 at 13:21

jpbro's gravatar image

jpbro ♦

just detect the problem... wrong certificate :-)

no errors signing the pdf but the result string not a valid PDF!

Question 1: using Crypt2 is the correct way to sign PDF Question 2: if not what's the best method using chilkat components

thanks for the help!!


answered Mar 25 '15 at 14:48

Eduardo%20Pereira's gravatar image

Eduardo Pereira


I might be wrong, but I don't think you can sign a PDF using Chilkat components and get a valid PDF file back. You can get a PKCS7 signature, or PKCS7 detached signature.

If you need to sign a PDF according to the PDF spec, then I think you'll need to use a library specifically designed for that task. For example: http://www.debenu.com/products/development/debenu-pdf-library/

(Mar 25 '15 at 16:03) jpbro ♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Mar 25 '15 at 06:49

Seen: 949 times

Last updated: Mar 25 '15 at 16:03

powered by OSQA