private void button2_Click(object sender, EventArgs e) { //token pin_form f_podpis = new pin_form(); f_podpis.ShowDialog(); if (f_podpis.DialogResult == DialogResult.OK) { //ext_certificate = f_podpis.ext_certificate; //DialogResult = DialogResult.OK; } }
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; }