EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Decode TSA´s response

Posted: 04/26/2011 12:50:43
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14


We are making the time stamps of files.

We send the file that we wish to make the time stamp to the TSA and TSA responds to us in parameter named as tCMS.

Timestamp (HashedData, tServerResult, tFailInfo, tCMS)

Then we save the answer in a file with extension .tsr and we want to decode the contents of file .tsr,so we can to procede see information as the name of the TSA, the time stamping.

Attached is an example of TSA's response to a file .tsr.
This file is 3,76 KB

Greetings and thanks in advance

[ Download ]
Posted: 04/26/2011 13:02:42
by Vsevolod Ievgiienko (Team)

Thank you for contacting us.

You should first decode the .tsr file using SBEncoding.Base64Decode function and then use ElCustomTSPClient.TSPInfo.ParseCMS method to parse decoded response.
Posted: 04/26/2011 13:03:34
by Ken Ivanov (Team)

Thank you for contacting us.

First, you should base64 decode the contents of the file. The decoded contents can then be passed to TElClientTSPInfo.ParseCMS() method for processing.
Posted: 04/28/2011 11:07:38
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14


To decode the TSA´s response stored in a file with extension .tsr, we use the procedure DecodeFile. We spent the first parameter as the value of the file path .tsr and the second the path where we want to save the decoded file with extension .tmp

Sub DecodeFile(ByVal srcFile As String, ByVal destFile As String)
Dim src As String
Dim sr As New IO.StreamReader(srcFile)

src = sr.ReadToEnd


Dim bt64 As Byte() = System.Convert.FromBase64String(src)

If IO.File.Exists(destFile) Then
End If

Dim sw As New System.IO.FileStream(destFile, System.IO.FileMode.Create)

sw.Write(bt64, 0, bt64.Length)


End Sub

Attached files .tsr (TSA response) and .tmp (decoded .tsr)

We wonder if we follow the right format, specifically PKCS7 and also

what properties or features we should use to get the name of the TSA, timestamping,...?

Thanks in advance.


[ Download ]
Posted: 04/28/2011 11:13:27
by Ken Ivanov (Team)

You are converting the data right. Now that you have it converted, please create an instance of TElClientTSPInfo class and pass the decoded data to its ParseCMS() method. Then use the properties of TElClientTSPInfo object to get the information you need (time stamp, TSA name etc.)
Posted: 05/05/2011 04:41:32
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14


When we use the method parseCMS returns the value 8198.

We've done two different ways.

1 st way

We have used the procedure described above DecodeFile, then we store the file contents decoded into a variable of type byte () call tCMSdecodificado.

DecodeFile (rutaSellada, rutaDec)
Dim src As String
Dim sr As New IO.StreamReader (rutaDec)
src = sr.ReadToEnd
sr.Close ()

Dim EU As New UnicodeEncoding
Dim tCMSdecodificado As Byte () = UE.GetBytes (src)

Dim parse As Integer
parse = Firmador.TSPInfo.ParseCMS (tCMSdecodificado)

MsgBox (parse.ToString)

2 nd Form

Here the parameter by reference does not return anything to us
Dim tCMSdecodificado () As Byte = New Byte () {}
SBEncoding.Unit.Base64Decode (TCMS, tCMSdecodificado, tCMS.Length)
MsgBox ("Decoded:" + Convert.ToBase64String (tCMSdecodificado))

Posted: 05/05/2011 04:52:43
by Ken Ivanov (Team)

1. Do not use StreamReader(), as it is not binary-friendly.

2. Instead, use the following code to read binary data from a file:

byte[] cnt = null;
FileStream f = new FileStream(rutaDec);
  cnt = new byte[f.Length];
  f.Read(cnt, 0, cnt.Length);
TElClientTSPInfo info = new TElClientTSPInfo();
int res = info.ParseCMS(cnt);
Posted: 05/05/2011 05:42:31
by Salvador Soto (Basic support level)
Joined: 04/26/2011
Posts: 14

Thank you, this is the solution



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