I am trying to get a example that came with the card to work to my needs.
The card holds personal data, which you can read with a specific card reader.
Currently the example will either read to a console window or to a single textbox on a form.
My problem is the fact that its to 1 single textbox.
I want each label on the card to be put into its own textbox.
For example
Cardnumber
Card Validity end
Card Validity begin
Chip number
ect...
There is a lot more data on the card.
I want to have it so i got a textbox
TxtCardnumber
TxtCardValidityEnd
TxtCardValidityBegin
TxtChipNumber
ect...
And each label from the card will put into its matching textbox.
My current code is this.
Form
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
txtResult.Clear()
FormProg = Me
Dim dt As New tests.DataTests()
dt.StoreCertificateRNFile();
dt.GetCardNumber()
dt.GetValidityBeginDate()
dt.GetValidityEndDate()
End Sub
Public Sub AppendText(ByVal txt As String)
txtResult.AppendText(txt & Environment.NewLine)
End Sub
Part of my class
Public Function GetData(ByVal label As String) As String
Dim value As [String] = ""
If m Is Nothing Then
m = Net.Sf.Pkcs11.Module.GetInstance(mFileName)
End If
' pkcs11 module init
'm.Initialize();
Try
' Get the first slot (cardreader) with a token
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)
' Search for objects
' First, define a search template
' "The label attribute of the objects should equal ..."
Dim classAttribute As New ByteArrayAttribute(CKA.CLASS)
classAttribute.Value = BitConverter.GetBytes(CUInt(Net.Sf.Pkcs11.Wrapper.CKO.DATA))
Dim labelAttribute As New ByteArrayAttribute(CKA.LABEL)
labelAttribute.Value = System.Text.Encoding.UTF8.GetBytes(label)
session.FindObjectsInit(New P11Attribute() {classAttribute, labelAttribute})
Dim foundObjects As P11Object() = session.FindObjects(50)
Dim counter As Integer = foundObjects.Length
Dim data As Data
While counter > 0
'foundObjects[counter-1].ReadAttributes(session);
'public static BooleanAttribute ReadAttribute(Session session, uint hObj, BooleanAttribute attr)
data = TryCast(foundObjects(counter - 1), Data)
label = data.Label.ToString()
If label IsNot Nothing Then
'Console.WriteLine(label)
'FormCommon.AppendText(label)
'FormProg.AppendText(label)
End If
If data.Value.Value IsNot Nothing Then
value = System.Text.Encoding.UTF8.GetString(data.Value.Value)
'Console.WriteLine(value)
'FormCommon.AppendText(value)
FormProg.AppendText(value)
End If
counter -= 1
End While
session.FindObjectsFinal()
Else
'Console.WriteLine("No card found" & vbLf)
'FormCommon.AppendText("No card found" & vbLf)
FormProg.AppendText("No card found" & vbLf)
End If
Finally
' pkcs11 finalize
'm.Finalize_();
m.Dispose()
End Try
Return value
End Function
There is more to the program, but most of it is just for the encryption.
I am guessing the Appentext is what deals with all the data going to 1 single textbox.
Don't really know Appendtext, never really used.