private void token_list_form_Load(object sender, EventArgs e) { //rbPKCS11Cert.Enabled = false; //cmbPKCS11Certificates.Items.Clear(); Session = null; PKCS11CertStorage.Close(); //PKCS11CertStorage.DLLName = @"C:\windows\System32\BIT4XPKI.DLL"; PKCS11CertStorage.DLLName = @"c:\windows\SysWOW64\BIT4XPKI.DLL"; OpenPKCS11Storage(); }
private void nacti_certifikat_by_row_index(int row_index) { Cursor = Cursors.WaitCursor; int k = Convert.ToInt32(dataGridView2.Rows[row_index].Cells[2].Value.ToString()); bool RO = PKCS11CertStorage.Module.get_Slot(k).ReadOnly; try { Session = PKCS11CertStorage.OpenSession(k, RO); } catch (EElCertStorageError) { if (RO) { throw; } Session = PKCS11CertStorage.OpenSession(k, true); } bool heslo_ok = false; if ((Session != null) && PKCS11CertStorage.Module.get_Slot(k).PinNeeded()) { using (pin_form frmPin = new pin_form()) { while (frmPin.ShowDialog() == DialogResult.OK) { string Pin = frmPin.pin_token; try { Session.Login((int)SBPKCS11Base.Unit.utUser, Pin); heslo_ok = true; break; } catch (EElPKCS11Error Ex) { if (Ex.ErrorCode == SBPKCS11Common.Unit.SB_CKR_PIN_INCORRECT) { MessageBox.Show("Nesprávný PIN", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Neplatný PIN: " + Ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception Ex) { Cursor = Cursors.Default; MessageBox.Show("Neplatný PIN: " + Ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } if (heslo_ok) { PopulateCertList(PKCS11CertStorage); } else { Cursor = Cursors.Default; return; } } else { PKCS11CertStorage.Close(); } Cursor = Cursors.Default; }