EldoS | Feel safer!

Software components for data protection, secure storage and transfer

.net with java dc return multiples certificates on signature

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
Posted: 06/15/2016 16:00:06
by javier aranda (Standard support level)
Joined: 06/15/2016
Posts: 1

I need to remove all extra certificates on message, keep only the one used in signature. There is my post-sign stage code. I will appreciate any advice.

   Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            Dim flag As Boolean = MyBase.Request.InputStream.Length > 0L
            If flag Then
                Dim array As Byte() = New Byte(MyBase.Request.InputStream.Length - 1) {}
                MyBase.Request.InputStream.Read(array, 0, array.Length)
            End If
            Dim flag2 As Boolean = Me.Session("signature") IsNot Nothing
            If flag2 Then
                Me.labelResult.Text = Me.Session("signature").ToString()
            End If
        End Sub

        Protected Sub FinishSigning(signature As Byte())
            Dim tElDCAsyncState As TElDCAsyncState = New TElDCAsyncState()
                Dim sessionId As String = ""
                Dim stream As MemoryStream = New MemoryStream(signature)
                tElDCAsyncState.LoadFromStream(stream, SBDCXMLEnc.__Global.DCXMLEncoding())
                Dim tElSignedCMSMessage As TElSignedCMSMessage = New TElSignedCMSMessage()

                Dim path As String = Sonda.Net.Configuracion.BaseWebTempDir.TrimEnd + "\FirmaDigital"
                Dim fileStream As FileStream = File.OpenRead(path + "\" + Me.Request.QueryString("ID") + ".bin")
                tElSignedCMSMessage.Open(fileStream, Nothing, 0L, 0L)
                Dim index As Integer = 0
                    Dim signature2 As TElCMSSignature = tElSignedCMSMessage.GetSignature(index)

                    Dim fileStream2 As FileStream = Nothing
                    fileStream2 = File.Create(path + "\" + Me.Request.QueryString("ID") + ".sig")

                End Try
            End Try
        End Sub

This is relate to post #36629
Posted: 06/17/2016 04:16:46
by Ken Ivanov (EldoS Corp.)

Hi Javier,

Thank you for contacting us.

You can use the same TElSignedCMSMessage class to remove the unneeded certificates from the signature:

1. Load your completed signature into a new TElSignedCMSMessage object.

2. Remove the unneeded certificates from TElSignedCMSMessage.Certificates list.

3. Save the message.

On a side note, there is a minor issue in your finalisation code. At the end of your FinishSigning() method, please dispose of the whole CMS object instead of its signature object, i.e. replace







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