TPJ.Encrypt 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package TPJ.Encrypt --version 2.0.1
NuGet\Install-Package TPJ.Encrypt -Version 2.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TPJ.Encrypt" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TPJ.Encrypt --version 2.0.1
#r "nuget: TPJ.Encrypt, 2.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TPJ.Encrypt as a Cake Addin
#addin nuget:?package=TPJ.Encrypt&version=2.0.1

// Install TPJ.Encrypt as a Cake Tool
#tool nuget:?package=TPJ.Encrypt&version=2.0.1

TPJ Encrypt library - Easily encrypt values. Simple, light weight, easy to setup!

Product Compatible and additional computed target framework versions.
.NET Framework net452 is compatible.  net46 is compatible.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 355 1/29/2023
3.0.0 11,805 8/20/2017
2.0.1 1,015 7/14/2017
2.0.0 1,161 5/5/2017

V2.0.0 is only supporting full .net 4.5.2, 4.6, and 4.6.1. Once .NETStandard 2.0 is released this packaged will be updated to run using this. More detailed Examples will follow then.
ASP.Net Core full framework (4.5.2 4.6 4.6.1) Website / WebAPI Set up.

Within appsettings.json and add the following

{
 "TPJ": {
   "Encrypt": {
     "EncryptionKey": "",
     "Salt": "",
     "KeySize": "",
   }
 }
}

EncryptionKey– (Required) Key used to lock the string down so it can only be decrypted using the same key  

Salt - This size of the IV (in bytes) must = (keysize / 8).  Default keysize is 256, so the IV must be 32 bytes long. Using a 16 character string gives us 32 bytes when converted to a byte array.

KeySize - by default its set to 256 which means you need a 32byte salt key if set to 128 you need a 16byte salt or 512 you need a 64 byte salt

Example appsettings.json setup –
{
 "TPJ": {
   "Encrypt": {
     "EncryptionKey": "asdzgfh|£%^%TEGDSTEGbg54e523s",
     "Salt": "tu89gaji343t89u2",
     "KeySize": "256",
   }
 }
}

Once appsettings.json is done open StartUp.cs file and go to ConfigureServices

var settings = new TPJ.Encrypt.Models.EncryptSettings(Configuration);
services.Configure<TPJ.Encrypt.Models.EncryptSettings>(options =>
{
   options.EncryptionKey = settings.EncryptionKey;
   options.Salt = settings.Salt;
   options.KeySize = settings.KeySize;
});

services.AddSingleton<TPJ.Encrypt.IEncrypt, TPJ.Encrypt.Encrypt>();

Then using DI within asp.net core you can call IEncrypt like so

private readonly TPJ.Encrypt.IEncryption _encryption;

public HomeController(TPJ.Encrypt.IEncryption encryption)
{
 _encryption = encryption;
}

Then you might have this

public string EncryptString(string valueToEncrypt)
{
 return _encryption.Encrypt(valueToEncrypt);
}

It really is that simple you will get an encrypted string returned. To then decrypt the string call _encryption.Decrypt(encryptedValue);