Eid uitlezen vanuit vb.net

781 views
Skip to first unread message

ywuy...@gmail.com

unread,
Jan 29, 2015, 7:59:17 AM1/29/15
to eid-middl...@googlegroups.com
Ik probeer gegevens van een Eid binnen te lezen in vb.net.

Zie hieronder de code :

-------------------------------------

Dim m As Net.Sf.Pkcs11.Module

m = Net.Sf.Pkcs11.Module.GetInstance("beidpkcs11.dll")

m.Initialize()

Try

   Dim slotlist As Slot() = m.GetSlotList(True)

   If slotlist.Length > 0 Then

      Dim slot As Slot = slotlist(0)

      Dim session As Session = slot.Token.OpenSession(True)

      Dim classAttribute As ObjectClassAttribute = New ObjectClassAttribute(CKO.DATA)

      session.FindObjectsInit(New P11Attribute() {classAttribute})

      Dim privatekeys As P11Object() = session.FindObjects(50)

      session.FindObjectsFinal()

   Endif

Finaly

   m.Finalize_()

   m = Nothing

End Try

-----------------------------------

De array privatekeys wordt ingelezen van de EID, er komen 43 elementen in te staan.

Deze elementen zijn echter allemaal 'Nothing'.

Kan mij iemand helpen om dit probleem op te lossen ?








Verhelst Wouter

unread,
Jan 29, 2015, 10:43:28 AM1/29/15
to ywuy...@gmail.com, eid-middl...@googlegroups.com
Hi,

For clarity, if you want a key, you shouldn't look for CKO_DATA objects, but for CKO_PRIVATE_KEY or CKO_PUBLIC_KEY ones instead (CKO_DATA is for, well, data, like "name" or "address" or "photo"). Alternatively, in the particular case of the BeID PKCS#11 module, if you pass on an empty set of attributes to match (i.e., you don't pass on the classAttribute thingy), you'll get all keys and certificates.

I'm not entirely sure why you're getting "Nothing" values, but it might be because you're only checking after you've done the FindObjectsFinal? That call is supposed to destroy a "find" operation; if you need to get any information about your search result (i.e., you want to call C_GetAttributeValue() on the result), you have to do that before you run FindObjectsFinal.

Regards,

--
Wouter Verhelst
________________________________________
Van: eid-middl...@googlegroups.com [eid-middl...@googlegroups.com] namens ywuy...@gmail.com [ywuy...@gmail.com]
Verzonden: donderdag 29 januari 2015 13:59
Aan: eid-middl...@googlegroups.com
Onderwerp: [eid-mw-dev] Eid uitlezen vanuit vb.net
--
You received this message because you are subscribed to the Google Groups "eID Middleware Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eid-middleware-...@googlegroups.com<mailto:eid-middleware-...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

Steven De Bondt

unread,
Jan 30, 2015, 4:33:00 AM1/30/15
to eid-middl...@googlegroups.com
Ik heb de c sharp naar vb.net vertaald, ik geef je hieronder de belangrijkste (vertaalde) functie, "getdata". Deze functie heb ik net getest met dit voorbeeldje: 

MsgBox(GetData("surname")) 

en gaf correct de achternaam weer van de eID.

Hopelijk zet dit je op de juiste weg!

mvg, SDB

Public Function GetData(ByVal label As String)
        Dim m As Net.Sf.Pkcs11.Module = Nothing
        Dim value As String = ""
        Dim mFileName As String = "beidpkcs11.dll"
        Dim slotlist() As Net.Sf.Pkcs11.Slot

        Try

            m = Net.Sf.Pkcs11.Module.GetInstance(mFileName)

            slotlist = m.GetSlotList(True)
            If (slotlist.Length > 0) Then
                Dim session As Net.Sf.Pkcs11.Session
                Dim slot As Net.Sf.Pkcs11.Slot
                slot = slotlist(0)
                session = slot.Token.OpenSession(True)
                Dim classAttribute As New ByteArrayAttribute(Net.Sf.Pkcs11.Wrapper.CKO.DATA)
                classAttribute.Value = BitConverter.GetBytes(Convert.ToUInt32(Net.Sf.Pkcs11.Wrapper.CKO.DATA))
                Dim labelAttribute As New ByteArrayAttribute(Net.Sf.Pkcs11.Wrapper.CKA.LABEL)
                labelAttribute.Value = System.Text.Encoding.UTF8.GetBytes(label)
                Dim p11a() As P11Attribute = {classAttribute, labelAttribute}
                session.FindObjectsInit(p11a)
                Dim foundObjects() As P11Object = session.FindObjects(50)

                Dim counter As Integer = foundObjects.Length
                Dim data As New Data
                While (counter > 0)

                    'foundObjects[counter-1].ReadAttributes(session);
                    'public static BooleanAttribute ReadAttribute(Session session, uint hObj, BooleanAttribute attr)
                    data = foundObjects(counter - 1)
                    label = data.Label.ToString()
                    If Not label = "" Then
                        System.Diagnostics.Trace.WriteLine("label: " + label)
                    End If
                    If Not data.Label.Value = Nothing Then
                        value = System.Text.Encoding.UTF8.GetString(data.Value.Value)
                        System.Diagnostics.Trace.WriteLine("mijne label: " + value)
                    End If
                    counter = counter - 1
                End While
                session.FindObjectsFinal()
            Else
                MsgBox("no card found")
            End If
            Return value
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            m.Dispose()
        End Try
    End Function

Jacques Van den broeck

unread,
Feb 18, 2015, 4:18:11 PM2/18/15
to eid-middl...@googlegroups.com
Hello,
I red the VBA examples in this discussion chapter. I want to know if I can apply those example in a MS ACCESS application, including Visual Basic modules and without other Tools. For instance I tried to link beidpkcs11.dll to my Visual Basic module via Tools - References. However this .dll was not accepted.
Thank you in advance.

Same text in Dutch ...
Hoy,
I heb de VBA voorbeelden gelezen en zou willen weten indien ik deze voorbeelden kan gebruiken in een MS ACCESS toepassing met Visual Basic modules, maar zonder andere tools. Bij voorbeeld ik probeerde beidpkcs.dll te linken met mijn VB module via Tools - References. Maar deze .dll werd geweigerd.
Dank bij voorbaat.

Jacques Van den Broeck
G.I.L at SKYNET.COM

Hello,

 

Jesper De Temmerman

unread,
Feb 19, 2015, 3:46:49 AM2/19/15
to eid-middl...@googlegroups.com
Jacques

there is a topic on support for VBA (https://groups.google.com/forum/#!topic/eid-middleware-dev/5Mm-uIIHtTs), you can check that to see what the possibilities are.

regards

Jesper De Temmerman
Reply all
Reply to author
Forward
0 new messages