private static void DisplayPermissionMembers( KeyContainerPermission keyContainerPermParam, KeyContainerPermissionAccessEntry[] keyContainerPermAccEntryArrayParam) { KeyContainerPermission keyContainerPerm2 = keyContainerPermParam; KeyContainerPermissionAccessEntry[] keyContainerPermAccEntryArray = keyContainerPermAccEntryArrayParam; // Display the KeyContainerPermission properties. //<Snippet12> Console.WriteLine("\nFlags value is " + keyContainerPerm2.Flags.ToString()); //</Snippet12> //<Snippet14> KeyContainerPermission keyContainerPerm3 = (KeyContainerPermission)keyContainerPerm2.Copy(); Console.WriteLine("Is the copy equal to the original? " + keyContainerPerm3.Equals(keyContainerPerm2)); //</Snippet14> //<Snippet15> // Perform an XML roundtrip. keyContainerPerm3.FromXml(keyContainerPerm2.ToXml()); Console.WriteLine("Was the XML roundtrip successful? " + keyContainerPerm3.Equals(keyContainerPerm2)); //</Snippet15> KeyContainerPermission keyContainerPerm4 = new KeyContainerPermission(KeyContainerPermissionFlags.Open, keyContainerPermAccEntryArray); //<Snippet16> KeyContainerPermission keyContainerPerm5 = (KeyContainerPermission)keyContainerPerm2.Intersect( keyContainerPerm4); Console.WriteLine("Flags value after the intersection is " + keyContainerPerm5.Flags.ToString()); //</Snippet16> //<Snippet17> keyContainerPerm5 = (KeyContainerPermission)keyContainerPerm2.Union( keyContainerPerm4); //</Snippet17> //<Snippet18> Console.WriteLine("Flags value after the union is " + keyContainerPerm5.Flags.ToString()); //</Snippet18> //<Snippet19> Console.WriteLine("Is one permission a subset of the other? " + keyContainerPerm4.IsSubsetOf(keyContainerPerm2)); //</Snippet19> }
//</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); } }