/// <summary>
        /// Updates the Key Attributes associated with the specified key
        /// </summary>
        /// <param name="vault">The vault name, e.g. https://myvault.vault.azure.net</param>
        /// <param name="keyName">The key name</param>
        /// <param name="keyOps">Json web key operations</param>
        /// <param name="attributes">The new attributes for the key</param>
        /// <returns> The updated key </returns>
        public async Task <KeyBundle> UpdateKeyAsync(string vault, string keyName,
                                                     string[] keyOps = null, KeyAttributes attributes = null)
        {
            if (string.IsNullOrEmpty(vault))
            {
                throw new ArgumentNullException("vault");
            }

            if (string.IsNullOrEmpty(keyName))
            {
                throw new ArgumentNullException("keyName");
            }

            if (attributes == null && keyOps == null)
            {
                throw new ArgumentException("Must provide one of keyOps or attributes");
            }

            var keyIdentifier = new KeyIdentifier(vault, keyName);

            return(await UpdateKeyAsync(keyIdentifier.Identifier, keyOps, attributes).ConfigureAwait(false));
        }
        /// <summary>
        /// Updates the Key Attributes associated with the specified key
        /// </summary>
        /// <param name="vault">The vault name, e.g. https://myvault.vault.azure.net</param>
        /// <param name="keyName">The key name</param>
        /// <param name="keyOps">Json web key operations</param>
        /// <param name="attributes">The new attributes for the key</param>
        /// <returns> The updated key </returns>
        public async Task <KeyBundle> UpdateKeyAsync(string keyIdentifier, string[] keyOps = null, KeyAttributes attributes = null)
        {
            if (string.IsNullOrEmpty(keyIdentifier))
            {
                throw new ArgumentNullException("keyIdentifier");
            }

            var request = new UpdateKeyRequestMessage {
                KeyOps = keyOps, Attributes = attributes
            };

            using (var httpResponse = await this.SendAsync <UpdateKeyRequestMessage>("PATCH",
                                                                                     CreateKeyUrl(keyIdentifier, "update"), request).ConfigureAwait(false))
            {
                await EnsureSuccessStatusCode(httpResponse).ConfigureAwait(false);

                var response = await DeserializeAsync <GetKeyResponseMessage>(httpResponse).ConfigureAwait(false);

                return(new KeyBundle
                {
                    Attributes = response.Attributes,
                    Key = response.Key,
                });
            }
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 public KeyBundle()
 {
     Key = new JsonWebKey();
     Attributes = new KeyAttributes();
 }
        /// <summary>
        /// Creates a new, named, key in the specified vault.
        /// </summary>
        /// <param name="vault">The URL for the vault in which the key is to be created.</param>
        /// <param name="keyName">The name for the key</param>
        /// <param name="keyType">The type of key to create (one of the valid WebKeyTypes)</param>
        /// <param name="keyAttributes">The attributes of the key</param>
        /// <returns>A key bundle containing the result of the create request</returns>
        public async Task <KeyBundle> CreateKeyAsync(string vault, string keyName, string keyType,
                                                     int?keySize = null, string[] key_ops = null, KeyAttributes keyAttributes = null)
        {
            if (string.IsNullOrEmpty(vault))
            {
                throw new ArgumentNullException("vault");
            }

            if (string.IsNullOrEmpty(keyName))
            {
                throw new ArgumentNullException("keyName");
            }

            if (string.IsNullOrEmpty(keyType))
            {
                throw new ArgumentNullException("keyType");
            }

            if (!JsonWebKeyType.AllTypes.Contains(keyType))
            {
                throw new ArgumentOutOfRangeException("keyType");
            }

            var keyIdentifier = new KeyIdentifier(vault, keyName);
            var request       = new CreateKeyRequestMessage {
                Kty = keyType, KeySize = keySize, KeyOps = key_ops, Attributes = keyAttributes
            };

            using (var httpResponse = await this.SendAsync <CreateKeyRequestMessage>("POST",
                                                                                     CreateKeyUrl(keyIdentifier.BaseIdentifier, "create"), request).ConfigureAwait(false))
            {
                await EnsureSuccessStatusCode(httpResponse).ConfigureAwait(false);

                var response = await DeserializeAsync <GetKeyResponseMessage>(httpResponse).ConfigureAwait(false);

                return(new KeyBundle
                {
                    Attributes = response.Attributes,
                    Key = response.Key,
                });
            }
        }
Exemple #5
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public KeyBundle()
 {
     Key        = new JsonWebKey();
     Attributes = new KeyAttributes();
 }