Ejemplo n.º 1
0
        private static void SaveProtectedKey(ICryptographicKeyConfigurationNode nodeWithKey, IServiceProvider serviceProvider)
        {
            ProtectedKeySettings keySettings = nodeWithKey.KeySettings;

            if (keySettings.ProtectedKey == null)
            {
                return;
            }

            using (Stream keyOutput = File.OpenWrite(keySettings.Filename))
            {
                KeyManager.Write(keyOutput, keySettings.ProtectedKey.EncryptedKey, keySettings.Scope);
            }
        }
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>
 /// Constructs a new instance
 /// with the corresponding runtime configuration data.
 /// </summary>
 /// <param name="symmetricAlgorithmProviderData">The corresponding runtime configuration data.</param>
 public SymmetricAlgorithmProviderNode(SymmetricAlgorithmProviderData symmetricAlgorithmProviderData) : base(symmetricAlgorithmProviderData)
 {
     key           = new ProtectedKeySettings(symmetricAlgorithmProviderData.ProtectedKeyFilename, symmetricAlgorithmProviderData.ProtectedKeyProtectionScope);
     algorithmType = symmetricAlgorithmProviderData.AlgorithmType;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructs a new instance
 /// with the corresponding runtime configuration data.
 /// </summary>
 /// <param name="hashAlgorithmProviderData">The corresponding runtime configuration data.</param>
 public KeyedHashAlgorithmProviderNode(KeyedHashAlgorithmProviderData hashAlgorithmProviderData) : base(hashAlgorithmProviderData)
 {
     key = new ProtectedKeySettings(hashAlgorithmProviderData.ProtectedKeyFilename, hashAlgorithmProviderData.ProtectedKeyProtectionScope);
 }