// [END kms_get_keyring_policy]

        // [START kms_add_member_to_keyring_policy]
        public static void AddMemberToKeyRingPolicy(string projectId, string locationId,
                                                    string keyRingId, string role, string member)
        {
            KeyManagementServiceClient client = KeyManagementServiceClient.Create();
            KeyRingName keyRingName           = new KeyRingName(projectId, locationId, keyRingId);

            Policy policy = client.GetIamPolicy(KeyNameOneof.From(keyRingName));

            policy.Bindings.Add(new Binding
            {
                Role    = role,
                Members = { member }
            });

            Policy updateResult = client.SetIamPolicy(KeyNameOneof.From(keyRingName), policy);

            foreach (Binding bindingResult in updateResult.Bindings)
            {
                Console.WriteLine($"Role: {bindingResult.Role}");
                foreach (string memberResult in bindingResult.Members)
                {
                    Console.WriteLine($"  Member: {memberResult}");
                }
            }
        }
        // [END kms_add_member_to_cryptokey_policy]

        // [START kms_remove_member_from_cryptokey_policy]
        public static void RemoveMemberFromCryptoKeyPolicy(string projectId, string locationId,
                                                           string keyRingId, string cryptoKeyId, string role, string member)
        {
            KeyManagementServiceClient client = KeyManagementServiceClient.Create();
            CryptoKeyName cryptoKeyName       =
                new CryptoKeyName(projectId, locationId, keyRingId, cryptoKeyId);

            Policy policy = client.GetIamPolicy(KeyNameOneof.From(cryptoKeyName));

            foreach (Binding binding in policy.Bindings.Where(b => b.Role == role))
            {
                binding.Members.Remove(member);
            }

            Policy updateResult = client.SetIamPolicy(KeyNameOneof.From(cryptoKeyName), policy);

            foreach (Binding bindingResult in updateResult.Bindings)
            {
                Console.WriteLine($"Role: {bindingResult.Role}");
                foreach (string memberResult in bindingResult.Members)
                {
                    Console.WriteLine($"  Member: {memberResult}");
                }
            }
        }
        // [END kms_remove_member_from_cryptokey_policy]

        // [START kms_get_keyring_policy]
        public static void GetKeyRingIamPolicy(string projectId, string locationId, string keyRingId)
        {
            KeyManagementServiceClient client = KeyManagementServiceClient.Create();
            KeyRingName keyRingName           = new KeyRingName(projectId, locationId, keyRingId);

            Policy result = client.GetIamPolicy(KeyNameOneof.From(keyRingName));

            foreach (Binding binding in result.Bindings)
            {
                Console.WriteLine($"Role: {binding.Role}");
                foreach (String member in binding.Members)
                {
                    Console.WriteLine($"  Member: {member}");
                }
            }
        }