示例#1
0
        private async void ButtonGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                ComboBoxKeyTypeItem selectedKeyTypeItem = GetSelectedComboBoxItem();

                if (selectedKeyTypeItem.Kind == ComboBoxKeyTypeItem.Kinds.Asymmetric)
                {
                    List <ObjectAttribute> privateKeyObjectAttributes = GetObjectAttributesFromListView(ListViewPrivateKeyAttributes);
                    List <ObjectAttribute> publicKeyObjectAttributes  = GetObjectAttributesFromListView(ListViewPublicKeyAttributes);

                    await WaitDialog.Execute(
                        this,
                        () => _pkcs11Slot.GenerateAsymmetricKeyPair(selectedKeyTypeItem.KeyType, privateKeyObjectAttributes, publicKeyObjectAttributes)
                        );
                }
                else
                {
                    List <ObjectAttribute> secretKeyObjectAttributes = GetObjectAttributesFromListView(ListViewSecretKeyAttributes);

                    await WaitDialog.Execute(
                        this,
                        () => _pkcs11Slot.GenerateSymmetricKey(selectedKeyTypeItem.KeyType, secretKeyObjectAttributes)
                        );
                }

                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                WinFormsUtils.ShowError(this, ex);
            }
        }
示例#2
0
        private void ComboBoxKeyType_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBoxKeyTypeItem selectedKeyTypeItem = GetSelectedComboBoxItem();

            switch (selectedKeyTypeItem.Kind)
            {
            case ComboBoxKeyTypeItem.Kinds.Asymmetric:
                ListViewPrivateKeyAttributes.Enabled = true;
                ListViewPublicKeyAttributes.Enabled  = true;
                ListViewSecretKeyAttributes.Enabled  = false;
                break;

            case ComboBoxKeyTypeItem.Kinds.Symmetric:
                ListViewPrivateKeyAttributes.Enabled = false;
                ListViewPublicKeyAttributes.Enabled  = false;
                ListViewSecretKeyAttributes.Enabled  = true;
                break;

            default:
                ListViewPrivateKeyAttributes.Enabled = false;
                ListViewPublicKeyAttributes.Enabled  = false;
                ListViewSecretKeyAttributes.Enabled  = false;
                break;
            }

            if (!ListViewPrivateKeyAttributes.Enabled)
            {
                ListViewPrivateKeyAttributes.BeginUpdate();
                ListViewPrivateKeyAttributes.HeaderStyle = ColumnHeaderStyle.None;
                ListViewPrivateKeyAttributes.Items.Clear();
                ListViewPrivateKeyAttributes.EndUpdate();
            }
            else
            {
                ListViewPrivateKeyAttributes.BeginUpdate();
                ListViewPrivateKeyAttributes.HeaderStyle = ColumnHeaderStyle.Clickable;
                ListViewPrivateKeyAttributes.Items.Clear();
                List <Tuple <ObjectAttribute, ClassAttribute> > objectAttributes = StringUtils.GetGenerateDefaultAttributes(Pkcs11Admin.Instance.Config.PrivateKeyAttributes, (ulong)selectedKeyTypeItem.KeyType);
                PutAttributesIntoListView(ListViewPrivateKeyAttributes, objectAttributes);
                ListViewPrivateKeyAttributes.EndUpdate();

                GenerateKeysTabControl.SelectedTab = TabPagePrivateKey;
            }

            if (!ListViewPublicKeyAttributes.Enabled)
            {
                ListViewPublicKeyAttributes.BeginUpdate();
                ListViewPublicKeyAttributes.HeaderStyle = ColumnHeaderStyle.None;
                ListViewPublicKeyAttributes.Items.Clear();
                ListViewPublicKeyAttributes.EndUpdate();
            }
            else
            {
                ListViewPublicKeyAttributes.BeginUpdate();
                ListViewPublicKeyAttributes.HeaderStyle = ColumnHeaderStyle.Clickable;
                ListViewPublicKeyAttributes.Items.Clear();
                List <Tuple <ObjectAttribute, ClassAttribute> > objectAttributes = StringUtils.GetGenerateDefaultAttributes(Pkcs11Admin.Instance.Config.PublicKeyAttributes, (ulong)selectedKeyTypeItem.KeyType);
                PutAttributesIntoListView(ListViewPublicKeyAttributes, objectAttributes);
                ListViewPublicKeyAttributes.EndUpdate();
            }

            if (!ListViewSecretKeyAttributes.Enabled)
            {
                ListViewSecretKeyAttributes.BeginUpdate();
                ListViewSecretKeyAttributes.HeaderStyle = ColumnHeaderStyle.None;
                ListViewSecretKeyAttributes.Items.Clear();
                ListViewSecretKeyAttributes.EndUpdate();
            }
            else
            {
                ListViewSecretKeyAttributes.BeginUpdate();
                ListViewSecretKeyAttributes.HeaderStyle = ColumnHeaderStyle.Clickable;
                ListViewSecretKeyAttributes.Items.Clear();
                List <Tuple <ObjectAttribute, ClassAttribute> > objectAttributes = StringUtils.GetGenerateDefaultAttributes(Pkcs11Admin.Instance.Config.SecretKeyAttributes, (ulong)selectedKeyTypeItem.KeyType);
                PutAttributesIntoListView(ListViewSecretKeyAttributes, objectAttributes);
                ListViewSecretKeyAttributes.EndUpdate();

                GenerateKeysTabControl.SelectedTab = TabPageSecretKey;
            }

            ReloadListViews();
        }