C#.NET - Generate an API Key Using Nuget Library

This article is about the integration of the Asmak9.AuthorizeRESTWebApiAK .NET library with a C#.NET Console Application.

Introduction 
 
API keys are used in the authorization process of either a web product, desktop application or mobile application, Therefore, the generation of a secure API key typically requires a combination of a password and a secret/salt key. I have recently created my own small REST Web API Authorization library Asmak9.AuthorizeRESTWebApiAK which is compatible with any ASP.NET and .NET Console Application project. The library also provides a facility to generate a random API key. 
 
Today, I shall be demonstrating the integration of the Asmak9.AuthorizeRESTWebApiAK .NET library with a C#.NET Console Application.

Prerequisites
 
The following are prerequisites before you proceed in this tutorial,
  1. Install Asmak9.AuthorizeRESTWebApiAK NuGet Package.
  2. Knowledge of C# Programming.
The example code is being developed in Microsoft Visual Studio 2019 Professional.
 
 
Let's begin now.
 
Step 1
 
Create a new C#.NET Console Application project and name it "GenerateApiKey".
 
Step 2
 
Open "Tools\Nuget Package Manage\Manage Nuget Packages for Solution...".
 
Step 3
 
Install Asmak9.AuthorizeRESTWebApiAK NuGet Package i.e.
 
 
Step 4
 
Open "Program.cs" file and add following lines of code i.e.
  1. ...  
  2.   
  3.                 // Initialization.  
  4.                 string myPassword = "mypassword";  
  5.                 string mysaltKey = "mysaltkey";  
  6.   
  7.                 // Generate API key.  
  8.                 string apiKey = RESTWebAPIKey.GenerateAPIKey(myPassword, mysaltKey);  
  9.   
  10. ... 
The above code will generate an API key value base on your provided password and secret/salt key values. If you have purchased the license key of this library then you can provide your license key in the last parameter, i.e.
  1. ...  
  2.   
  3.                 // Initialization.  
  4.                 string myPassword = "mypassword";  
  5.                 string mysaltKey = "mysaltkey";  
  6.   
  7.                 // Generate API key.  
  8.                 string apiKey = RESTWebAPIKey.GenerateAPIKey(myPassword, mysaltKey, "MY_LICENSE_KEY");  
  9.   
  10. ... 
Step 5
 
Now, execute the project and you will be able to see the following output.

 

Conclusion

 
In this article, you learned to integrate Asmak9.AuthorizeRESTWebApiAK .NET library with C#.NET Console Application. Finally, you will also learn to generate an API key value base on your provided password and secret/salt key values. If you have purchased the license key then you can pass your license key as the last parameter in the API key generation method.