Ejemplo n.º 1
0
        /// <summary>
        /// <para>Creates an instance of the child node class and adds it as a child of the parent node. The node will be a <see cref="SymmetricAlgorithmProviderNode"/>.</para>
        /// </summary>
        /// <param name="node">
        /// <para>The parent node to add the newly created <see cref="AddChildNodeCommand.ChildNode"/>.</para>
        /// </param>
        protected override void ExecuteCore(ConfigurationNode node)
        {
            TypeSelectorUI selector = new TypeSelectorUI(
                typeof(RijndaelManaged),
                typeof(SymmetricAlgorithm),
                TypeSelectorIncludes.None
                );

            DialogResult typeResult = selector.ShowDialog();

            if (typeResult == DialogResult.OK)
            {
                Type algorithmType = selector.SelectedType;
                CryptographicKeyWizard keyManager = new CryptographicKeyWizard(new SymmetricAlgorithmKeyCreator(algorithmType));
                DialogResult           keyResult  = keyManager.ShowDialog();

                if (keyResult == DialogResult.OK)
                {
                    INodeNameCreationService service = ServiceHelper.GetNameCreationService(ServiceProvider);
                    Debug.Assert(service != null, "Could not find the INodeNameCreationService");
                    base.ExecuteCore(node);
                    SymmetricAlgorithmProviderNode providerNode = (SymmetricAlgorithmProviderNode)ChildNode;
                    providerNode.AlgorithmType = selector.SelectedType;
                    providerNode.Name          = service.GetUniqueName(selector.SelectedType.Name, providerNode, providerNode.Parent);
                    providerNode.Key           = keyManager.KeySettings;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Edits the specified object using the editor style provided by the GetEditStyle method.
        /// </summary>
        /// <param name="context">
        /// An ITypeDescriptorContext that can be used to gain additional context information.
        /// </param>
        /// <param name="provider">
        /// A service provider object through which editing services may be obtained.
        /// </param>
        /// <param name="value">
        /// An instance of the value being edited.
        /// </param>
        /// <returns>
        /// The new value of the object. If the value of the object hasn't changed, this should return the same object it was passed.
        /// </returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Debug.Assert(provider != null, "No service provider; we cannot edit the value");
            if (provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                Debug.Assert(edSvc != null, "No editor service; we cannot edit the value");
                if (edSvc != null)
                {
                    IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                    ProtectedKeySettings keySettings = value as ProtectedKeySettings;
                    if (keySettings == null)
                    {
                        throw new ArgumentException(Resources.KeyManagerEditorRequiresKeyInfoProperty);
                    }

                    ICryptographicKeyConfigurationNode cryptographicKeyContainer = context.Instance as ICryptographicKeyConfigurationNode;

                    try
                    {
                        ImportProtectedKey(cryptographicKeyContainer);
                    }
                    catch (IOException ioe)
                    {
                        MessageBox.Show(String.Format(Resources.OpenExistingKeyFileFailureErrorMessage, keySettings.Filename, ioe.Message), Resources.OpenExistingKeyFileFailureTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(value);
                    }

                    CryptographicKeyWizard dialog = new CryptographicKeyWizard(CryptographicKeyWizardStep.CreateNewKey, cryptographicKeyContainer.KeyCreator);
                    dialog.KeySettings = keySettings;

                    DialogResult dialogResult = service.ShowDialog(dialog);

                    if (dialogResult == DialogResult.Cancel)
                    {
                        return(keySettings);
                    }
                    else
                    {
                        return(dialog.KeySettings);
                    }
                }
            }
            return(value);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// <para>Creates an instance of the child node class and adds it as a child of the parent node. The node will be a <see cref="HashAlgorithmProviderNode"/>.</para>
        /// </summary>
        /// <param name="node">
        /// <para>The parent node to add the newly created <see cref="AddChildNodeCommand.ChildNode"/>.</para>
        /// </param>
        protected override void ExecuteCore(ConfigurationNode node)
        {
            INodeNameCreationService service = ServiceHelper.GetNameCreationService(ServiceProvider);

            Debug.Assert(service != null, "Could not find the INodeNameCreationService");

            TypeSelectorUI selector = new TypeSelectorUI(
                typeof(SHA1Managed),
                typeof(HashAlgorithm),
                TypeSelectorIncludes.None
                );

            DialogResult typeResult = selector.ShowDialog();

            if (typeResult == DialogResult.OK)
            {
                Type selectedAlgorithmType = selector.SelectedType;
                if (selector.SelectedType.IsSubclassOf(typeof(KeyedHashAlgorithm)))
                {
                    CryptographicKeyWizard keyWizard = new CryptographicKeyWizard(new KeyedHashAlgorithmKeyCreator(selector.SelectedType));
                    DialogResult           keyResult = keyWizard.ShowDialog();

                    if (keyResult == DialogResult.OK)
                    {
                        KeyedHashAlgorithmProviderNode providerNode = new KeyedHashAlgorithmProviderNode();

                        providerNode.Key           = keyWizard.KeySettings;
                        providerNode.AlgorithmType = selector.SelectedType;

                        node.AddNode(providerNode);
                        providerNode.Name = service.GetUniqueName(selector.SelectedType.Name, providerNode, providerNode.Parent);
                    }
                }
                else
                {
                    base.ExecuteCore(node);
                    HashAlgorithmProviderNode providerNode = (HashAlgorithmProviderNode)ChildNode;
                    providerNode.AlgorithmType = selectedAlgorithmType;
                    providerNode.Name          = service.GetUniqueName(selector.SelectedType.Name, providerNode, providerNode.Parent);
                }
            }
        }