Encrypting and decrypting data
There are multiple encryption algorithms you can choose from in .NET Core. Some algorithms are implemented by the operating system and their names are suffixed with the CryptoServiceProvider
class, some are implemented entirely in .NET, some use symmetric keys, and some use asymmetric keys.
Tip
Best Practice
Choose AES for symmetric encryption and RSA for asymmetric encryption.
Encrypting symmetrically with AES
To make it easier to reuse your protection code in the future, we will create a static class named Protector
in its own class library.
Using Visual Studio 2017
In Visual Studio 2017, press Ctrl + Shift + N or navigate to File | New | Project....
In the New Project dialog, in the Installed | Templates list, expand Visual C# and select .NET Standard. In the list at the center, select Class Library (.NET Standard), type the name Ch11_CryptographyLib
, change the location to C:\Code
, type the solution name as Chapter11
, and then click on OK. Rename Class1...