I have solved the problem myself. Below is the solution:
1 private void btnKoppel_Click(object sender, EventArgs e)
2 {
3 //Instantiate an object of the type EIDCard
4 EIDCard card = new EIDCard();
5 //Prepare the card to be able to read from it
6 card.InitReader();
7 try
8 {
9 //Get the lenght from the Authentication certificate so you're able to make your byte[] that large
10 lengte = card.ReadAuthenticationCertificate().Length;
11
12 arrayAuth = new Byte[lengte];
13 //Read the authenticationCertificate from the card and put in a byte[]
14 arrayAuth = card.ReadAuthenticationCertificate();
15
16 //Get the path of your DirectoryEntry.
17 String pad = dgvGebruikers.SelectedCells[2].Value.ToString();
18
19 //create LDAP connection object
20 DirectoryEntry entry = new DirectoryEntry(pad);
21
22 //Import the byte[] with the AuthenticationCertificate in your X5092Certificate
23 x5092.Import(arrayAuth);
24 if (checkIfCertificateHasBeenMappedBefore(x5092, entry))
25 {
26 }
27 else
28 {
29
30 //Get the format, name and issuerName from the certificate
31 String format = x5092.GetFormat();
32 String name = x5092.GetName();
33 String issuerName = x5092.GetIssuerName();
34
35 //Strip the data from the certificate so the spaces behind the "," are removed
36 String formatStripped = format.Replace(", ", ",");
37 String nameStripped = name.Replace(", ", ",");
38 String issuerNameStripped = issuerName.Replace(", ", ",");
39
40 //Put the stripped data in an object
41 object altSecId = formatStripped + ":<I>" + issuerNameStripped + "<S>" + nameStripped;
42
43 /*
44 * Check if the property "altSecurityIdentities" is null.
45 * If not, remove the current value of that property and commit your changes.
46 */
47 try
48 {
49 if (entry.Properties["altSecurityIdentities"].Value != null)
50 {
51 entry.Properties["altSecurityIdentities"].Remove(entry.Properties["altSecurityIdentities"].Value); ;
52 //This will make sure the changes have been executed in the AD.
53 entry.CommitChanges();
54 }
55 //Add the new certificate to the "altSecurityIdentities" property.
56 entry.Properties["altSecurityIdentities"].Add(altSecId);
57 entry.CommitChanges();
58 //Let the user know the certificate has been mapped to the useraccount.
59 MessageBox.Show("Het certificaat werd normaal gezien aan de account van " + entry.Properties["displayName"].Value + " gekoppeld!");
60 }
61 catch (UnauthorizedAccessException uae)
62 {
63 MessageBox.Show("U hebt niet voldoende rechten om een certificaat te koppelen!");
64 }
65 catch (COMException ce3)
66 {
67 MessageBox.Show("De connectie met het netwerk werd verloren!\n\nGelieve uw connectie te bekijken.");
68 }
69
70 //Let the card object know there will be no more reading.
71 card.DoneReader();
72 }
73 }
74 catch (NullReferenceException nre)
75 {
76 MessageBox.Show("Er is geen kaartlezer aangesloten of er zit geen kaart in de kaartlezer!");
77 }
78 catch (ArgumentException ae)
79 {
80 MessageBox.Show("U hebt waarschijnlijk de kaart uit de kaartlezer gehaald of deze heeft geen goede connectie meer.\n" +
81 "Gelieve de kaart opnieuw in de kaartlezer te plaatsen en opnieuw te proberen.");
82 }
83 }