DataProtection PersistKeysToFileSystem not creating key (Windows 10 on MacBook Pro)

1.9k views Asked by At

I am developing a .NET Core solution in Visual Studio 2015 on a MacBook Pro 2016 year model using bootcamp.

At the moment we are running on 1.0.0-rc1-final of the sdk. We are working on upgrading but it will take some time.

I have a real problem with the Data Protection framework. I configure DataProtection to persist keys to the local file system using:

services.ConfigureDataProtection(configure => configure.PersistKeysToFileSystem(new DirectoryInfo(_configFolderPath)));

The problem is when I run the solution and do a call to the application the encryption key is not created. My colleague who is working on a PC laptop (We are both running Windows 10) run the exact same code base (From the same commit) and for him the key is created.

I get no errors what so ever. Is this a problem with the MacBook hardware not being able to be used to create the key or have anyone run in to this problem?

2

There are 2 answers

2
blowdart On

That's an odd way to configure it. Generally we expect you to configure when you set it up.

Try

public void ConfigureServices(IServiceCollection services)
{
    services.AddDataProtection()
        .PersistKeysToFileSystem(new DirectoryInfo(_configFolderPath));

}

By the time it's in the services collection it's too late to change things, which is when your configuration approach is kicking in.

0
Tryggen On

Looking at tveitan's code and realising it is much the same as mine, and I am upgrading to RTM, I can confirm that what blowdart says works with the new package at least.