There are also encryption algorithms in ASP.NET Core, such as AES, Des, 3Des (TripleDes), Rijndael, RC2, and so on. For more information, visit https://docs.microsoft.com/en-us/dotnet/standard/security/cryptography-model.
Note
An example project can be found at https://github.com/polatengin/B05277/tree/master/Chapter17/5-EncryptDecryptData.
There is nothing special to get ready for encryption in ASP.NET Core. Just create an empty project and some NuGet packages; that's it.
- Let's create a new project and dive into the code to better understand encryption and decryption in ASP.NET Core:
dotnet new console -n EncryptDecryptData
dotnet restore
- Now open the
Program.cs
file, and add theEncrypt()
andDecrypt()
methods, as follows:
static string Encrypt(string text, string key) { var _key = Encoding.UTF8.GetBytes(key); using (var aes = AES.Create()) { using (var encryptor = aes.CreateEncryptor(_key, aes.IV)) ...