Skip to main content


Create and Retrieve Secrets from the Azure Key Vault using an ASP.Net Core Application

Istock 1488521147

As everyone knows, maintaining application-level security for passwords, certificates, API keys, and other data is a bit of a critical thing. It was necessary for my project to safeguard the SMTP password.

I wanted to know how to protect my SMTP password in some way. I then discovered the Azure Key vault concept and began to put it into practice. Azure Key Vault is a cloud service for storing and accessing secrets, which can be anything sensitive, like passwords, connection strings, etc.

Key Vault Details can be found at the following link: What is Azure Key Vault? | Microsoft Learn

A few procedures must be followed to establish an Azure Key Vault, grant access permissions to registered applications within Azure, and obtain the key via the core application.

First and foremost, an Azure membership is required. You can have a trial or subscription as needed for practical purposes.

Create Azure Key Vault Secrets and Access Them Using Core Web API

  1. Access Azure services by visiting
  2. Choose the Key Vaults service from the list.1
  3. Provide the access settings to the Azure Key Vault policy and create key vaults by filling out the necessary fields. Either choose a resource group or form a new resource group.3 4 5  7  9 1011 1213
  4. Within the SMTP-Cred key vault, create secrets. Numerous secrets can be produced within a single key vault for various purposes.14 15
  5. Return to Azure Service and choose “App Registration.”16
  6. Let’s look at registering an app.17
  7. Provide the application’s name.18
  8. Copy the tenantId, clientId, and secret value. These are necessities for access to Key Vault secrets. They will be utilized in an Core application.1920
  9. Return to the key vault you created in step #3 and establish an access policy there. The procedure remains the same although another key vault name is visible in this image.32
  10. Look for and choose Secret Management and Template.34
  11. Find your previously registered app by searching for it, then select Create.35 36
  12. Create an Asp.Net Core Web API Application now by utilizing the template and install packages Azure.Identity and Azure.Security.KeyVault.Secrets from Tools->NuGet  Package Manager->Manage NuGet packages for solution. The images below show you how we can obtain the key vault secrets.373839


We may achieve this using the Key Vault policy. If not, the default credential policy is available for configuration.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Parag Balapure

Parag Balapure is a senior technical consultant at Perficient who has contributed eight years in ASP.Net MVC, Sitecore (9.x and 10.x), Sitecore Headless Development, SXA, C#, SQL, along with front-end technologies like ReactJS, VueJS, and others. He likes investigating and solving complex technical problems.

More from this Author

Follow Us