EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Add timestamp to a document PDF

Posted: 06/07/2011 02:37:54
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14


We are trying to add timestamp to a PDF.

Today,we do is find the pdf document that you want to sign and add timestamp.Para add our signature, we looked for the digital certificate through a form.

See you in class PDFSignature, the function Timestamp that adds a timestamp to the signature, but we do not know how to use this function, as it gives runtime error when used.

This is our code in vb:

Document Dim As New TElPDFDocument
Sig Dim As TElPDFSignature

'Adding the signature and setting up property values

Document.AddSignature index = ()
Sig = Document.Signatures (index)
Sig.Timestamp ()
Sig.Handler = PublicKeyHandler
Sig.AuthorName = "TestName"
Sig.SigningTime = DateTime.Now.ToUniversalTime ()
Sig.Reason = ""
Sig.Invisible = True

'For add timestamp to a pdf

So please you explain me how we can add timestamp to a pdf document.

Posted: 06/07/2011 02:43:48
by Vsevolod Ievgiienko (Team)

Thank you for contacting us.

Please look through our sample that can be found in \EldoS\SecureBlackbox.NET\Samples\VB.NET\PDFBlackbox\Signer folder. This article will also be helpfull: http://www.eldos.com/documentation/sb...stamp.html
Posted: 06/07/2011 06:51:03
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14


We are trying add timestamp in a pdf document,but we does not knowdo how.

We get the date and time, through a secure institution with the help of the class HttpTspclient.
On the other we signed up and add the signature in pdf document. But do not know how you must add the timestamp.

We have read the url provided to us, but we have not been helpful

Part of our code in vb is:

Firmador.TSPInfo.TSANameSet = True
tresultado = Firmador.Timestamp(Realizar_Hash(ruta), tServerResult, tFailInfo, tCMS)

'Here,we save the files tsr and tmp (respond of entity and decoded file)

res = Firmador.TSPInfo.ParseCMS(cnt)
If (res <> 0) Then
MsgBox("ERROR PARSE: " + res.ToString)
End If

'Already we have the time and date, now we want add timestamp to a pdf document

'Here, we sign the pdf document

Dim leerPdf As Byte()

leerPdf = IO.File.ReadAllBytes(ruta)

Dim Document As New TElPDFDocument
Dim PublicKeyHandler As New TElPDFPublicKeySecurityHandler
Dim Cert As New TElX509Certificate
Dim CertStorage As New TElMemoryCertStorage
Dim SystemStore As TElWinCertStorage

Dim TempPath As String = ""
Dim Success As Boolean
Dim F As System.IO.FileStream
Dim index As Integer
Dim Sig As TElPDFSignature

' creating a temporary file copy
TempPath = System.IO.Path.GetTempFileName()
System.IO.File.WriteAllBytes(TempPath, leerPdf)

' opening the temporary file
Success = False
F = New System.IO.FileStream(TempPath, FileMode.Open,

' checking if the document is already encrypted
If (Document.Encrypted) Then
MessageBox.Show("The document is encrypted and cannot be signed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

End If
' adding the signature and setting up property values
index = Document.AddSignature()
Sig = Document.Signatures(index)
Sig.Handler = PublicKeyHandler
Sig.AuthorName = "Nombre de Prueba"
Sig.SigningTime = DateTime.Now.ToUniversalTime()
Sig.Reason = ""
Sig.Invisible = True

CERTIFICADO_INDEX = frmCertificadoIndex.Obtener
End If

SystemStore = New TElWinCertStorage
End Try
Cert = SystemStore.Certificates(CERTIFICADO_INDEX)

If ("" & CERTIFICADO_CLAVE).Trim = "" Then
CERTIFICADO_CLAVE = frmCertificadoClave.Obtener
End If
'adding certificate to certificate storage
CertStorage.Add(Cert, True)
PublicKeyHandler.CertStorage = CertStorage
PublicKeyHandler.SignatureType =
PublicKeyHandler.CustomName = "Adobe.PPKMS"

' allowing to save the document
Success = True

' closing the document
End Try

Catch ex As Exception

End Try

Catch ex As Exception
MessageBox.Show("Error: " + ex.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Success = False

End Try

' if encryption process succeeded, moving the temporary file to the place
' of destination file
If (Success) Then
leerPdf = File.ReadAllBytes(TempPath)

End If

IO.File.WriteAllBytes("C:\PdfFirmado.pdf", leerPdf)

Regards and thank you
Posted: 06/07/2011 07:00:13
by Vsevolod Ievgiienko (Team)

You should assign an instance of ElHTTPTSPClient to PublicKeyHandler.TSPClient property. A timestamp will be retrieved and added to a signature automaticaly if this property is assigned.
Posted: 06/08/2011 10:10:38
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14

when you assign an instance of ElHTTPSPClient to PublickeyHandler.TSPClient property, you add a timestamp, but this timestamp is the local of the computer. Previously, we contacted with a secure institution which gives us a tmestamp, and this timestamp is that we want to add to our pdf document.

Posted: 06/08/2011 10:42:18
by Vsevolod Ievgiienko (Team)

You can not add an existing timestamp to a just created signature because its value depends on signature value. You can add a timestamp only to an existing signature using Timestamp() method.
Posted: 06/09/2011 02:40:37
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14


we have used the method Timestamp() of TelPDFSignature class, but it shows the error "Invalid signature contents "

So we've done:

Sig.TimeStamp ()

Still, we do not understand very well this method, because if we want to add a timestamp to pdf document that already we have, how do we do?.

To get this timestamp, we've done with the class HTTPTSPClient, we come in contact with an institution and provides a timestamp.

Posted: 06/09/2011 03:40:39
by Vsevolod Ievgiienko (Team)

I've just re-read you code... you have used HTTPTSPClient incorrectly. You've passed a whole document hash to a HTTPTSPClient using this code:

tresultado = Firmador.Timestamp(Realizar_Hash(ruta), tServerResult, tFailInfo, tCMS)

If you want to timestamp a signature then HashedData parameter of Timestamp method is calculated from a created signature value, not from the whole document content. This is done automaticaly when you assign an instance of ElHTTPSPClient to PublickeyHandler.TSPClient property.

The timestamp you got can not be embedded into an existing PDF file.



Topic viewed 2774 times

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


Back to top

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

Got it!