EldoS | Feel safer!

Software components for data protection, secure storage and transfer

.net with java dc return multiples certificates on signature

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

Code
   Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            SBUtils.Unit.SetLicenseKey("xxx")
            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)
                Me.FinishSigning(array)
            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()
            Try
                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
                Try
                    Dim signature2 As TElCMSSignature = tElSignedCMSMessage.GetSignature(index)
                    signature2.CompleteAsyncSign(tElDCAsyncState)

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

                Finally
                    tElSignedCMSMessage.GetSignature(index).Dispose()
                End Try
                fileStream.Close()
            Finally
                tElDCAsyncState.Dispose()
            End Try
        End Sub


This is relate to post #36629
https://www.eldos.com/forum/read.php?TID=6614&MID=36629#postform
#37019
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

tElSignedCMSMessage.GetSignature(index).Dispose();

with

tElSignedCMSMessage.Dispose();


Ken

Reply

Statistics

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