0

I need to do is to encrypt/decryption some sting. Is it possible to use IDataProtectionProvider in my ASP.NET MVC (not core) project?

I can see the interface is defined in the following packages:

  1. Microsoft.Owin.Security.DataProtection
  2. Microsoft.AspNetCore.DataProtection

I am not sure which one of the above packages I should use? Also, not sure how to actually instantiate DataProtector?

Hooman Bahreini
  • 14,480
  • 11
  • 70
  • 137
  • Probably the one that *doesn't* have aspnetcore in its name – pinkfloydx33 Jun 18 '20 at 23:39
  • Thanks, but the main problem is that I don't know where is the implementation... – Hooman Bahreini Jun 18 '20 at 23:47
  • This is related to this: https://stackoverflow.com/questions/36473209/get-dataprotectionprovider-in-mvc-5-for-dependecy-injection-correctly – Carlo Luisito Jun 19 '20 at 01:46
  • Dont tag this as aspnetcore if its not for core plz – Gekctek Jun 19 '20 at 03:42
  • Thought the .net runtime can handle an AspNetCore package, doesnt mean it should be used with AspNet framework. They are two completely different frameworks that dont share patterns, flow and dependecy injection. I would not recommend mixing the two. – Gekctek Jun 19 '20 at 03:59
  • @Gekctek: what is the problem with installing ASP.NET Core packages on ASP.NET MVC? Even Microsoft's default MVC template comes with Identity.Core packages. – Hooman Bahreini Jun 19 '20 at 04:19
  • `Microsoft.AspNetCore.Identity` is for .net core but `Microsoft.AspNet.Identity.Core` is just a convention for packages to have the 'core' library included. There can be cases where maybe it would work but at minimum it is bad practice and can lead to unwanted behavior or errors – Gekctek Jun 19 '20 at 04:25

1 Answers1

1

This is related to this: Get DataProtectionProvider in MVC 5 for dependecy injection correctly

and after you inject it, you can now use it in your constructor something like this:

public IDataProtectionProvider _iDataProtectionProvider;

public FooController(IDataProtectionProvider iDataProtectionProvider)
{
    _iDataProtectionProvider = iDataProtectionProvider
}
Carlo Luisito
  • 179
  • 1
  • 15