public void Default() { KeyContainerPermissionAttribute a = new KeyContainerPermissionAttribute(SecurityAction.Assert); Assert.AreEqual(KeyContainerPermissionFlags.NoFlags, a.Flags, "Flags"); Assert.IsNull(a.KeyContainerName, "KeyContainerName"); Assert.AreEqual(-1, a.KeySpec, "KeySpec"); Assert.IsNull(a.KeyStore, "KeyStore"); Assert.IsNull(a.ProviderName, "ProviderName"); Assert.AreEqual(-1, a.ProviderType, "ProviderType"); Assert.IsFalse(a.Unrestricted, "Unrestricted"); Assert.AreEqual(a.ToString(), a.TypeId.ToString(), "TypeId"); KeyContainerPermission perm = (KeyContainerPermission)a.CreatePermission(); Assert.AreEqual(KeyContainerPermissionFlags.NoFlags, perm.Flags, "perm.Flags"); Assert.IsFalse(perm.IsUnrestricted(), "perm.Unrestricted"); }
//</Snippet4> public static int Main() { try { // Create a key container for use in the sample. GenKey_SaveInContainer("MyKeyContainer"); // Initialize property values for creating a // KeyContainerPermissionAccessEntry object. myKeyContainerName = rsa.CspKeyContainerInfo.KeyContainerName; providerName = rsa.CspKeyContainerInfo.ProviderName; providerType = rsa.CspKeyContainerInfo.ProviderType; cspParams.KeyContainerName = myKeyContainerName; cspParams.ProviderName = providerName; cspParams.ProviderType = providerType; // Display the KeyContainerPermissionAccessEntry properties // using the third KeyContainerPermissionAccessEntry object. DisplayAccessEntryMembers(); //<Snippet22> // Add access entry objects to a key container permission. KeyContainerPermission keyContainerPerm1 = new KeyContainerPermission(PermissionState.Unrestricted); Console.WriteLine("Is the permission unrestricted? " + keyContainerPerm1.IsUnrestricted()); keyContainerPerm1.AccessEntries.Add(keyContainerPermAccEntry1); keyContainerPerm1.AccessEntries.Add(keyContainerPermAccEntry2); //</Snippet22> // Display the permission. System.Console.WriteLine(keyContainerPerm1.ToXml().ToString()); //<Snippet13> // Create an array of KeyContainerPermissionAccessEntry objects KeyContainerPermissionAccessEntry[] keyContainerPermAccEntryArray = { keyContainerPermAccEntry1, keyContainerPermAccEntry2 }; // Create a new KeyContainerPermission using the array. KeyContainerPermission keyContainerPerm2 = new KeyContainerPermission( KeyContainerPermissionFlags.AllFlags, keyContainerPermAccEntryArray); //</Snippet13> DisplayPermissionMembers( keyContainerPerm2, keyContainerPermAccEntryArray); // Demonstrate the effect of a deny for opening a key container. DenyOpen(); // Demonstrate the deletion of a key container. DeleteContainer(); Console.WriteLine("Press the Enter key to exit."); Console.Read(); return(0); // Close the current try block that did not expect an exception. } catch (Exception e) { Console.WriteLine("Unexpected exception thrown: " + e.Message); return(0); } }