Header Ads

C#.NET: Generate API Key using Nuget Library

API keys are used in authorization process of either a web product, desktop application or mobile application, So, 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 integration of Asmak9.AuthorizeRESTWebApiAK .NET library with C#.NET Console Application.


Prerequisites:

Following are some prerequisites before you proceed any further 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.

Download Now!

Let's begin now.

1) Create a new C#.NET Console Application project and name it "GenerateApiKey".  
2) Open "Tools\Nuget Package Manage\Manage Nuget Packages for Solution...".
3) Install Asmak9.AuthorizeRESTWebApiAK NuGet Package i.e.


4) Open "Program.cs" file and add following lines of code i.e.

...

                // Initialization.
                string myPassword = "mypassword";
                string mysaltKey = "mysaltkey";

                // Generate API key.
                string apiKey = RESTWebAPIKey.GenerateAPIKey(myPassword, mysaltKey);

...

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.

...

                // Initialization.
                string myPassword = "mypassword";
                string mysaltKey = "mysaltkey";

                // Generate API key.
                string apiKey = RESTWebAPIKey.GenerateAPIKey(myPassword, mysaltKey, "MY_LICENSE_KEY");

...

5) Now, execute the project and you will be able to see  following output  i.e.


Conclusion

In this article, you will learn 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 last parameter in API key generation method.

1 comment:

  1. Thanks For sharing valuable Information....

    Movie box is excellent application for them who love to enjoy
    their time with movies and TV series.There was a time when watching
    and downloading movies.
    movies box apk
    moviebox download android

    ReplyDelete