I have an ASP.NET Core app and a .NET Core command line app that need to share the same database entries. I would like to encrypt one of the columns but still be able to have the two apps read the entries. I have been looking into the DataProtection apis for encryption but can figure out how to decrypt between the two app. Any suggestions?
In both apps I have tried configuring the DataProtector with the same purpose:
_protector = provider.CreateProtector("TestEncryption");
However, when I attempt to decrypt I wind up with the following exception:
CryptographicException: The payload was invalid.
Share data protection keys between applications. You can store it in local filesystem, in Azure Storage or Redis caches, or use another third-party distributed storage. For example:
public void ConfigureServices(IServiceCollection services)
{
// Connect to Redis database.
var redis = ConnectionMultiplexer.Connect("<URI>");
services.AddDataProtection()
.PersistKeysToRedis(redis, "DataProtection-Keys");
services.AddMvc();
}
Documentation: Key storage providers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With