ASP.NET Core MVC Value Provider for Encrypted Route Parameter
Switch branches/tags
Nothing to show
Clone or download
Latest commit ba16eff Sep 14, 2017

ASP.NET Core MVC CryptoValueProvider

Custom Crypto Value Provider in ASP.NET Core MVC to support encrypted query string or route parameter. More detail on implementation here.

Example usage:

  1. Create action method and mark it with CryptoValueProvider attribute or mark some of the parameter with FromCrypto attribute
public IActionResult Example1(int param1, string param2)
public IActionResult Example2([FromCrypto]int param1, string param2, [FromCrypto]string param3)
  1. Create parameter dictionary and encrypt it with CryptoParamsProtector
public class HomeController : Controller
    CryptoParamsProtector _protector;
    public HomeController(CryptoParamsProtector protector)
        _protector = protector;
    public IActionResult Index()
        var paramDictionary = new Dictionary();
        paramDictionary.Add("param1", 1234.ToString());
        paramDictionary.Add("param2", "Hello World!");
        ViewBag.encryptedRouteParam1 = _protector.EncryptParamDictionary(paramDictionary);
        return View();
  1. Use encrypted string as route parameter to generate link
<a asp-controller="demo" asp-action="example1" asp-route-id="@ViewBag.encryptedRouteParam1"><h4>Example 1 Demo</h4></a>

Other Examples