The best series of March 2023. Top 10 series of March. Mr. Marvel

Mr. Marvel has compiled the best TV series releases for March 2023. I can recommend the second season of the fantasy series “Shadow and Bone”, the Russian drama series about the life of actors…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




ASP.Net Core API Data Protection

The Data protection API is all about allowing data to be safely exposed out with the application. How the data will be traversed in the network as a plain text or encrypted.

We will discuss here how we can encrypt the API response data before sending it to calling application and decrypt the request data.

Here is the link for more detail about the data protection API

Lets’ start step by step, first we need to create a table which will hold the key used to encrypt and decrypt the data.

Create a new project

you can unchecked the https and docker option.

Add nuget package Microsoft.AspNetCore.DataProtection.

Now it is time to add code in your project. Add a class in Models folder.

Now add Context class.

Create a repository to manage key, this class will help to fetch the key for encryption and , it will add the key in database if not present.

To activate security we need to add code in startup class to resolve the dependency for Data Protection API.

Add following below lines in ConfigureServices method.

Here is the folder structure of project shown in screen shot.

I have added controller “DataProtectionController” having Get method. The first get method without any parameter will encrypt the data.Second Get method will take string to decrypt as a parameter.

You can see in controller “protect string” will be encrypted. so run your application.

Now copy the string and paste in the url after controller name.

You can protect any data using this approach. you can explore more in Microsoft site. For data protection you can save the key on you local machine instead of SQL, I have chosen SQL to store the key because for load balance API.

Add a comment

Related posts:

Toast Genie How to Guide

Congratulations on your purchase! Your Toast Genie will meet all your toasting needs because we designed it with you in mind. Whether you like to smother a couple lightly toasted slices of sourdough…

The Silent Minority

Ever since the rise of farce-fascism under the leadership of Buffoon-in-Chief Trump, those of us with steadfast left-liberal beliefs who nevertheless had respect for the principle of conservatism…

Want more?

How can we solve those sticky STINKY problems that just won’t reconcile? They seem to stick to us and cling for dear life, and then they smell up everything in our environment when we’re trying to…