コード例 #1
0
ファイル: CsrDialog.cs プロジェクト: sluckywhh/Pkcs11Admin
        private async void ButtonGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                if (ListViewSubject.Items.Count < 1)
                {
                    WinFormsUtils.ShowInfo(null, "Please specify subject first");
                    return;
                }

                DnEntry[] dnEntries = new DnEntry[ListViewSubject.Items.Count];
                for (int i = 0; i < ListViewSubject.Items.Count; i++)
                {
                    dnEntries[i] = (DnEntry)ListViewSubject.Items[i].Tag;
                }

                string fileName    = null;
                byte[] fileContent = null;

                // TODO - Parametrize HashAlgorithm
                // TODO - Specify SAN

                await WaitDialog.Execute(
                    this,
                    () => _pkcs11Slot.GenerateCsr(_privKeyInfo, _pubKeyInfo, dnEntries, HashAlgorithm.SHA256, out fileName, out fileContent)
                    );

                using (SaveFileDialog saveFileDialog = new SaveFileDialog())
                {
                    saveFileDialog.FileName = fileName;

                    saveFileDialog.Filter      = "All files (*.*)|*.*|DER encoded certificate signing request (*.csr)|*.csr";
                    saveFileDialog.FilterIndex = 2;

                    saveFileDialog.AddExtension    = true;
                    saveFileDialog.CreatePrompt    = false;
                    saveFileDialog.OverwritePrompt = true;

                    if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        File.WriteAllBytes(saveFileDialog.FileName, fileContent);
                        WinFormsUtils.ShowInfo(this, "CSR successfully saved");
                        DialogResult = DialogResult.OK;
                    }
                }
            }
            catch (Exception ex)
            {
                WinFormsUtils.ShowError(this, ex);
            }
        }
コード例 #2
0
ファイル: InitTokenDialog.cs プロジェクト: TSFO27/Pkcs11Admin
        private async void ButtonOk_Click(object sender, EventArgs e)
        {
            if (TextBoxPin.Text != TextBoxConfirmPin.Text)
            {
                WinFormsUtils.ShowInfo(this, "New PIN entries do not match");
                return;
            }

            try
            {
                await WaitDialog.Execute(this, () => _slot.InitToken(TextBoxPin.Text, TextBoxTokenLabel.Text));

                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                WinFormsUtils.ShowError(this, ex);
            }
        }
コード例 #3
0
        private void ButtonOk_Click(object sender, EventArgs e)
        {
            if (TextBoxNewPin.Text != TextBoxConfirmNewPin.Text)
            {
                WinFormsUtils.ShowInfo(this, "New PIN entries do not match");
                return;
            }

            try
            {
                _slot.InitPin(TextBoxNewPin.Text);
                WinFormsUtils.ShowInfo(this, "User PIN successfuly initialized");
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                WinFormsUtils.ShowError(this, ex);
            }
        }
コード例 #4
0
ファイル: ChangePinDialog.cs プロジェクト: watsug/Pkcs11Admin
        private void ButtonOk_Click(object sender, EventArgs e)
        {
            if (TextBoxNewPin.Text != TextBoxConfirmNewPin.Text)
            {
                WinFormsUtils.ShowInfo(this, "New PIN entries do not match");
                return;
            }

            try
            {
                _slot.ChangePin(TextBoxCurrentPin.Text, TextBoxNewPin.Text);
                WinFormsUtils.ShowInfo(this, (_userType == CKU.CKU_SO) ? "SO PIN successfuly changed" : "PIN successfuly changed");
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                WinFormsUtils.ShowError(this, ex);
            }
        }
コード例 #5
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.FileName = _name;

                saveFileDialog.Filter      = "All files (*.*)|*.*";
                saveFileDialog.FilterIndex = 1;

                saveFileDialog.CreatePrompt    = false;
                saveFileDialog.OverwritePrompt = true;

                if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    File.WriteAllBytes(saveFileDialog.FileName, _content);
                    WinFormsUtils.ShowInfo(this, "Data object successfully exported");
                }
            }
        }
コード例 #6
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.FileName = TextBoxName.Text;

                saveFileDialog.Filter      = "All files (*.*)|*.*";
                saveFileDialog.FilterIndex = 1;

                saveFileDialog.CreatePrompt    = false;
                saveFileDialog.OverwritePrompt = true;

                if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    File.WriteAllBytes(saveFileDialog.FileName, Bytes);
                    WinFormsUtils.ShowInfo(this, "Attribute value was successfully saved");
                }
            }
        }
コード例 #7
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.FileName = "certificate.cer";

                saveFileDialog.Filter      = "All files (*.*)|*.*|DER encoded X.509 certificate (*.cer)|*.cer";
                saveFileDialog.FilterIndex = 2;

                saveFileDialog.AddExtension    = true;
                saveFileDialog.CreatePrompt    = false;
                saveFileDialog.OverwritePrompt = true;

                if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    File.WriteAllBytes(saveFileDialog.FileName, _bytes);
                    WinFormsUtils.ShowInfo(this, "Certificate successfully exported");
                }
            }
        }
コード例 #8
0
ファイル: CsrDialog.cs プロジェクト: sluckywhh/Pkcs11Admin
        private int?GetSingleSelectedItemIndex(ListView listView)
        {
            if (listView == null)
            {
                throw new ArgumentNullException("listBox");
            }

            if (listView.SelectedItems.Count < 1)
            {
                WinFormsUtils.ShowInfo(null, "Please select item first");
                return(null);
            }

            if (listView.SelectedItems.Count > 1)
            {
                WinFormsUtils.ShowInfo(null, "Please select only one item");
                return(null);
            }

            return(listView.SelectedItems[0].Index);
        }