3

I am using Microsoft.AspNetCore.DataProtection in ASP.NET Core 2.0 application for data protection. And for the default settings I have added below code in Startup.cs file

public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        services.AddDataProtection().ProtectKeysWithDpapi();
        ...
        ...
    }

But that code throws an error:

InvalidOperationException: The 'IXmlRepository' instance could not be found. When an 'IXmlEncryptor' instance is set, a corresponding 'IXmlRepository' instance must also be set.

Did I miss something in this implementation?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
prog1011
  • 3,425
  • 3
  • 30
  • 57

1 Answers1

8

You specified how to encrypt the keys (the Windows DPAPI implementation of IXmlEncryptor) but you did not specify where to persist the encryption keys (the IXmlRepository). There are various options to persist the keys, for example the file system, registry or some remote location in the cloud.

Try using PersistKeysToFileSystem() or PersistKeysToRegistry(). I suggest you take a look at the documentation regarding ASP.NET Core Data Protection configuration.

Henk Mollema
  • 44,194
  • 12
  • 93
  • 104