Пример #1
0
        private async Task <byte[]> GetCertificateData(KeyVaultClient client, KeyVaultCertificateAttribute input)
        {
            if (input.FetchPrivateKey)
            {
                var certificateSecret = string.IsNullOrWhiteSpace(input.CertificateVersion)
                    ? await client.GetSecretAsync(
                    vaultBaseUrl : KeyVaultHelpers.GetVaultBaseUrl(input.VaultName),
                    secretName : input.CertificateName)
                    : await client.GetSecretAsync(
                    vaultBaseUrl : KeyVaultHelpers.GetVaultBaseUrl(input.VaultName),
                    secretName : input.CertificateName,
                    secretVersion : input.CertificateVersion);

                return(Convert.FromBase64String(certificateSecret.Value));
            }
            else
            {
                var certificateObject = string.IsNullOrWhiteSpace(input.CertificateVersion)
                    ? await client.GetCertificateAsync(
                    vaultBaseUrl : KeyVaultHelpers.GetVaultBaseUrl(input.VaultName),
                    certificateName : input.CertificateName)
                    : await client.GetCertificateAsync(
                    vaultBaseUrl : KeyVaultHelpers.GetVaultBaseUrl(input.VaultName),
                    certificateName : input.CertificateName,
                    certificateVersion : input.CertificateVersion);

                return(certificateObject.Cer);
            }
        }
        public async Task <string> ConvertAsync(KeyVaultSecretAttribute input, CancellationToken cancellationToken)
        {
            var client = new KeyVaultExtensionClient(keyVaultProperties: input).GetKeyVaultClient();

            var secret = string.IsNullOrWhiteSpace(input.SecretVersion)
                ? await client.GetSecretAsync(
                vaultBaseUrl : KeyVaultHelpers.GetVaultBaseUrl(input.VaultName),
                secretName : input.SecretName)
                : await client.GetSecretAsync(
                vaultBaseUrl : KeyVaultHelpers.GetVaultBaseUrl(input.VaultName),
                secretName : input.SecretName,
                secretVersion : input.SecretVersion);

            return(secret.Value);
        }
Пример #3
0
        public async Task <KeyResult> ConvertAsync(KeyVaultKeyAttribute input, CancellationToken cancellationToken)
        {
            var client = new KeyVaultExtensionClient(keyVaultProperties: input).GetKeyVaultClient();

            var key = string.IsNullOrWhiteSpace(input.KeyVersion)
                ? await client.GetKeyAsync(
                vaultBaseUrl : KeyVaultHelpers.GetVaultBaseUrl(input.VaultName),
                keyName : input.KeyName)
                : await client.GetKeyAsync(
                vaultBaseUrl : KeyVaultHelpers.GetVaultBaseUrl(input.VaultName),
                keyName : input.KeyName,
                keyVersion : input.KeyVersion);

            return(new KeyResult {
                Key = key.Key
            });
        }