Question:
Hello
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!!
Try
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.SetSigningCert(CryptCert)
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", ""))
GravarPDF.Write(qFicheiroPDF_Final)
GravarPDF.Close()
GravarPDF.Dispose()
Else
PDF_Assinar = 3
End If
Catch ex As Exception
PDF_Assinar = 99 'Indeterminado
End Try
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).
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!!