EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Add timestamp to a document PDF

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#16565
Posted: 06/07/2011 02:37:54
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14

Hello,

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
Sig.Timestamp()

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

Regards
#16566
Posted: 06/07/2011 02:43:48
by Vsevolod Ievgiienko (EldoS Corp.)

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
#16569
Posted: 06/07/2011 06:51:03
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14

Hi,

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)
Else
MsgBox("PARSE CORRECTO")
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


Try
' 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,
FileAccess.ReadWrite)
Try

Document.Open(F)
Try
' 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

If CERTIFICADO_INDEX = -1 Then
CERTIFICADO_INDEX = frmCertificadoIndex.Obtener
End If

SystemStore = New TElWinCertStorage
SystemStore.SystemStores.BeginUpdate()
Try
SystemStore.SystemStores.Clear()
SystemStore.SystemStores.Add("MY")
Finally
SystemStore.SystemStores.EndUpdate()
End Try
Cert = SystemStore.Certificates(CERTIFICADO_INDEX)

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


' allowing to save the document
Success = True

Finally
' closing the document
Document.Close(Success)
End Try

Catch ex As Exception
MessageBox.Show(ex.Message)

Finally
F.Close()
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
#16570
Posted: 06/07/2011 07:00:13
by Vsevolod Ievgiienko (EldoS Corp.)

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.
#16594
Posted: 06/08/2011 10:10:38
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14

Hello,
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.

Greetings
#16595
Posted: 06/08/2011 10:42:18
by Vsevolod Ievgiienko (EldoS Corp.)

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.
#16605
Posted: 06/09/2011 02:40:37
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14

Hi,

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.

Greetings
#16606
Posted: 06/09/2011 03:40:39
by Vsevolod Ievgiienko (EldoS Corp.)

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.
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.

Reply

Statistics

Topic viewed 2531 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!