public void KeyedHashAlgorithmProviderNodeTest() { bool saltEnabled = false; Type algorithmType = typeof(HMACSHA1); ProtectedKeySettings keySettings = new ProtectedKeySettings("some filename", DataProtectionScope.CurrentUser); string name = "some name"; KeyedHashAlgorithmProviderNode node = new KeyedHashAlgorithmProviderNode(); node.Name = name; node.SaltEnabled = saltEnabled; node.AlgorithmType = algorithmType; node.Key = keySettings; Assert.AreEqual(name, node.Name); Assert.AreEqual(algorithmType, node.AlgorithmType); Assert.AreEqual(saltEnabled, node.SaltEnabled); Assert.AreEqual(keySettings.Filename, node.Key.Filename); Assert.AreEqual(keySettings.Scope, node.Key.Scope); KeyedHashAlgorithmProviderData data = (KeyedHashAlgorithmProviderData)node.HashProviderData; Assert.AreEqual(name, data.Name); Assert.AreEqual(algorithmType, data.AlgorithmType); Assert.AreEqual(saltEnabled, data.SaltEnabled); Assert.AreEqual(keySettings.Filename, data.ProtectedKeyFilename); Assert.AreEqual(keySettings.Scope, data.ProtectedKeyProtectionScope); }
protected override bool AfterSelectType(Type selectedType) { CryptographicKeyWizard keyManager = new CryptographicKeyWizard(new SymmetricAlgorithmKeyCreator(selectedType)); DialogResult keyResult = keyManager.ShowDialog(); keySettings = keyManager.KeySettings; return(keyResult == DialogResult.OK); }
private static void SaveProtectedKey(ProtectedKeySettings protectedKeySettings) { if (protectedKeySettings.ProtectedKey == null) { return; } using (Stream keyOutput = File.OpenWrite(protectedKeySettings.FileName)) { KeyManager.Write(keyOutput, protectedKeySettings.ProtectedKey.EncryptedKey, protectedKeySettings.Scope); } }
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); } }
public void SymmetricAlgorithmProviderNodeTest() { Type algorithmType = typeof(RijndaelManaged); ProtectedKeySettings keySettings = new ProtectedKeySettings("some filename", DataProtectionScope.CurrentUser); string name = "some name"; SymmetricAlgorithmProviderNode node = new SymmetricAlgorithmProviderNode(); node.Name = name; node.AlgorithmType = algorithmType; node.Key = keySettings; Assert.AreEqual(name, node.Name); Assert.AreEqual(algorithmType, node.AlgorithmType); Assert.AreEqual(keySettings.Filename, node.Key.Filename); Assert.AreEqual(keySettings.Scope, node.Key.Scope); SymmetricAlgorithmProviderData data = (SymmetricAlgorithmProviderData)node.SymmetricCryptoProviderData ; Assert.AreEqual(name, data.Name); Assert.AreEqual(algorithmType, data.AlgorithmType); Assert.AreEqual(keySettings.Filename, data.ProtectedKeyFilename); Assert.AreEqual(keySettings.Scope, data.ProtectedKeyProtectionScope); }
public void SymmetricAlgorithmProviderNodeTest() { Type algorithmType = typeof(RijndaelManaged); ProtectedKeySettings keySettings = new ProtectedKeySettings("some filename", DataProtectionScope.CurrentUser); string name = "some name"; SymmetricAlgorithmProviderNode node = new SymmetricAlgorithmProviderNode(); node.Name = name; node.AlgorithmType = algorithmType; node.Key = keySettings; Assert.AreEqual(name, node.Name); Assert.AreEqual(algorithmType, node.AlgorithmType); Assert.AreEqual(keySettings.Filename, node.Key.Filename); Assert.AreEqual(keySettings.Scope, node.Key.Scope); SymmetricAlgorithmProviderData data = (SymmetricAlgorithmProviderData)node.SymmetricCryptoProviderData; Assert.AreEqual(name, data.Name); Assert.AreEqual(algorithmType, data.AlgorithmType); Assert.AreEqual(keySettings.Filename, data.ProtectedKeyFilename); Assert.AreEqual(keySettings.Scope, data.ProtectedKeyProtectionScope); }