コード例 #1
0
        public KeyBundle CreateKey(string vaultName, string keyName, KeyAttributes keyAttributes)
        {
            if (string.IsNullOrEmpty(vaultName))
            {
                throw new ArgumentNullException("vaultName");
            }
            if (string.IsNullOrEmpty(keyName))
            {
                throw new ArgumentNullException("keyName");
            }
            if (keyAttributes == null)
            {
                throw new ArgumentNullException("keyAttributes");
            }

            string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName);

            Client.KeyAttributes clientAttributes = (Client.KeyAttributes)keyAttributes;

            Client.KeyBundle clientKeyBundle =
                this.keyVaultClient.CreateKeyAsync(
                    vaultAddress,
                    keyName,
                    keyAttributes.KeyType,
                    key_ops: keyAttributes.KeyOps,
                    keyAttributes: clientAttributes).GetAwaiter().GetResult();

            return(new KeyBundle(clientKeyBundle, this.vaultUriHelper));
        }
コード例 #2
0
        public KeyBundle ImportKey(string vaultName, string keyName, KeyAttributes keyAttributes, JsonWebKey webKey, bool?importToHsm)
        {
            if (string.IsNullOrEmpty(vaultName))
            {
                throw new ArgumentNullException("vaultName");
            }
            if (string.IsNullOrEmpty(keyName))
            {
                throw new ArgumentNullException("keyName");
            }
            if (keyAttributes == null)
            {
                throw new ArgumentNullException("keyAttributes");
            }
            if (webKey == null)
            {
                throw new ArgumentNullException("webKey");
            }

            string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName);

            Client.KeyAttributes clientAttributes = (Client.KeyAttributes)keyAttributes;

            webKey.KeyOps = keyAttributes.KeyOps;
            Client.KeyBundle clientKeyBundle = new Client.KeyBundle()
            {
                Attributes = clientAttributes,
                Key        = webKey
            };

            clientKeyBundle = this.keyVaultClient.ImportKeyAsync(vaultAddress, keyName, clientKeyBundle, importToHsm).GetAwaiter().GetResult();

            return(new KeyBundle(clientKeyBundle, this.vaultUriHelper));
        }
コード例 #3
0
        public KeyBundle DeleteKey(string vaultName, string keyName)
        {
            if (string.IsNullOrEmpty(vaultName))
            {
                throw new ArgumentNullException("vaultName");
            }
            if (string.IsNullOrEmpty(keyName))
            {
                throw new ArgumentNullException("keyName");
            }

            string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName);

            Client.KeyBundle clientKeyBundle = this.keyVaultClient.DeleteKeyAsync(vaultAddress, keyName).GetAwaiter().GetResult();

            return(new KeyBundle(clientKeyBundle, this.vaultUriHelper));
        }
コード例 #4
0
        public KeyBundle ImportKey(string vaultName, string keyName, KeyAttributes keyAttributes, JsonWebKey webKey, bool? importToHsm)
        {
            if (string.IsNullOrEmpty(vaultName))
            {
                throw new ArgumentNullException("vaultName");
            }
            if (string.IsNullOrEmpty(keyName))
            {
                throw new ArgumentNullException("keyName");
            }
            if (keyAttributes == null)
            {
                throw new ArgumentNullException("keyAttributes");
            }
            if (webKey == null)
            {
                throw new ArgumentNullException("webKey");
            }

            string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName);

            Client.KeyAttributes clientAttributes = (Client.KeyAttributes)keyAttributes;

            webKey.KeyOps = keyAttributes.KeyOps;
            Client.KeyBundle clientKeyBundle = new Client.KeyBundle()
            {
                Attributes = clientAttributes,
                Key = webKey
            };

            try
            {
                clientKeyBundle = this.keyVaultClient.ImportKeyAsync(vaultAddress, keyName, clientKeyBundle, importToHsm).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                throw GetInnerException(ex);
            }

            return new KeyBundle(clientKeyBundle, this.vaultUriHelper);
        }