/// <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; } } }
/// <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; } } }
protected override bool AfterSelectType(Type selectedType) { CryptographicKeyWizard keyManager = new CryptographicKeyWizard(new SymmetricAlgorithmKeyCreator(selectedType)); DialogResult keyResult = keyManager.ShowDialog(); keySettings = keyManager.KeySettings; return keyResult == DialogResult.OK; }
/// <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; }
/// <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); }
protected override bool AfterSelectType(Type selectedType) { if (selectedType.IsSubclassOf(typeof(KeyedHashAlgorithm))) { CreatedElementType = typeof(KeyedHashAlgorithmProviderData); CryptographicKeyWizard keyManager = new CryptographicKeyWizard(new KeyedHashAlgorithmKeyCreator(selectedType)); DialogResult keyResult = keyManager.ShowDialog(); keySettings = keyManager.KeySettings; return keyResult == DialogResult.OK; } else { CreatedElementType = typeof(HashAlgorithmProviderData); return true; } }
/// <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); } } }
/// <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); } } }
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(KeyManagerResources.KeyManagerEditorRequiresKeyInfoProperty); } var bindableProperty = EditorUtility.GetBindableProperty(context); ICryptographicKeyProperty cryptographicKeyContainer = bindableProperty.Property as ICryptographicKeyProperty; CryptographicKeyWizard dialog = new CryptographicKeyWizard(CryptographicKeyWizardStep.CreateNewKey, cryptographicKeyContainer.KeyCreator); try { var uiService = (IUIServiceWpf)provider.GetService(typeof(IUIServiceWpf)); KeyManagerUtilities.ImportProtectedKey(uiService, keySettings); dialog.KeySettings = keySettings; } catch (FileNotFoundException) { //this is handled by the KeyManager utilites; return(value); } catch (IOException ioe) { MessageBox.Show(String.Format(CultureInfo.CurrentCulture, KeyManagerResources.OpenExistingKeyFileFailureErrorMessage, keySettings.FileName, ioe.Message), KeyManagerResources.OpenExistingKeyFileFailureTitle, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(value); } catch (Exception e) { IUIServiceWpf uiService = (IUIServiceWpf)provider.GetService(typeof(IUIServiceWpf)); string unableToLoadKeyMessage = string.Format(CultureInfo.CurrentCulture, KeyManagerResources.LoadExistingKeyFileFailureErrorMessage, keySettings.FileName, e.Message); var unableToLoadKeyDialogResult = uiService.ShowMessageWpf(unableToLoadKeyMessage, KeyManagerResources.OpenExistingKeyFileFailureTitle, System.Windows.MessageBoxButton.YesNo); if (unableToLoadKeyDialogResult == System.Windows.MessageBoxResult.No) { return(value); } } DialogResult editorDialogResult = service.ShowDialog(dialog); if (editorDialogResult == DialogResult.Cancel) { return(keySettings); } else { return(dialog.KeySettings); } } } return(value); }