Net Core Middleware custom encryption and decryption

Introduction: The first time to write articles, have questions, please light spray

The current version 2.1.3 to use Net Core

We often need to transfer the primary key Id entities in development to the front, but when Get the front end does not want to see the plaintext, we usually encrypt the data, so have some experience to write this article. (Mainly because I find the Internet to write code too simple, does not meet my needs)

Here I use the Net Core comes DataProtector, use their own Baidu,

The first step to filter requests (Request):

 


Request processing main section

To be noted here is no Dispose of newResponse, originally using dual use, but it feels too much nesting, personal coding style, you can choose


FilterRequest main part

Currently only the Get and Post Other Method can add their own. Currently only matching parameters, the field name to the field at the end of the Id screening can be done to expand its custom properties and reflection to do is possible, more flexible,

But to sacrifice a little performance, and see how your choice of your needs, here only do a Demo.

 


The last part is the Response Filter

Response is the same as filtering, it is relatively simple.

Written in the last: the entire project is not made up, and help a friend write a gadget, this class file I posted to the Baidu network disk.

Links: https://pan.baidu.com/s/1m72tHkw8zAzYYpWO0Yw2FQ extraction code: r3qh 

 

Guess you like

Origin www.cnblogs.com/luciusliang/p/11526225.html