No XML encryptor configured. Key {...} may be persisted to storage in unencrypted form. is a start-up warning that ASP.NET Core prints when it writes a new data protection key to a folder without encrypting it. The key file then holds the master key in plain text. On Windows, add ProtectKeysWithDpapi(); the warning goes and the key is stored encrypted.

The app works either way: the warning is about who can read the key file, not about the app failing. Anyone who can read the key folder can read an unencrypted key.

The error

warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {79553570-d505-454f-a27c-4cb729244883} may be persisted to storage in unencrypted form.

It was the first line in the server console of a start on a new key folder (keys-x1), when the app created its key. The key file it wrote said the same thing in a comment:

PS> Get-Content ..\AfLab\keys-x1\*.xml
...
      <masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
        <!-- Warning: the key below is in an unencrypted form. -->
        <value>JeSVmPIuUvyZsJ0f...</value>
      </masterKey>
...

Why it happens

The app called AddDataProtection().PersistKeysToFileSystem(...) and named no way to protect the keys at rest. Data protection then wrote the key XML as it was, with the master key value readable, and logged the warning once for the new key. The value shown above is shortened; it belongs to a throwaway test key ring.

The same warning appeared in a Linux container of the same app with its keys on a volume. That run was not given an encryptor, so the fix below is the Windows one.

The fix

...
    builder.Services.AddDataProtection()
        .PersistKeysToFileSystem(new DirectoryInfo(keysFolder))
        .ProtectKeysWithDpapi()
        .SetApplicationName("AfLab");
...
PS> Get-Content ..\AfLab\keys-x2\*.xml
...
        <encryptedKey xmlns="">
          <!-- This key is encrypted with Windows DPAPI. -->
          <value>AQAAANCMnd8BFdERjHoAwE/Cl+sB...</value>
        </encryptedKey>
...

With ProtectKeysWithDpapi() and a new key folder (keys-x2), the server console showed no warning, the key file held an encryptedSecret with the comment above instead of the plain master key, and a form fetched and posted with curl returned "Booked for Maria Garcia.". A new process started later on the same folder, which held only that key, printed no warning and accepted a form posted to it, so the encrypted key was read back after a restart. This post tested the Windows fix only.

How it was reproduced

A project from dotnet new web -n AfLab -f net10.0 on .NET SDK 11.0.100, no NuGet packages, running on ASP.NET Core 10.0.15 in Development on Windows 11 at 127.0.0.1:15610, with data protection keys in a folder of the test project chosen on the command line, started once without and once with ProtectKeysWithDpapi(), each time on a new empty folder. The form endpoints (GET /form, POST /book) were driven with curl 8.22.0 and a cookie jar.

Frequently asked

Is No XML encryptor configured an error in ASP.NET Core?
It is a warning. In the test the app ran normally and forms posted; the warning says the data protection key was written to disk with its master key in plain text.
How do I fix No XML encryptor configured on Windows?
Add ProtectKeysWithDpapi() after PersistKeysToFileSystem. In the test the warning was gone and the key file held an encrypted secret marked as encrypted with Windows DPAPI.
When does No XML encryptor configured appear?
In the test it appeared once at start-up, as the first console line, when the app created a new key in an empty key folder. A start that found its key already in the folder did not print it again.

More decoded errors in the Fixes category. The same warning next to the container key-folder warning is in Storing keys in a directory that may not be persisted outside of the container.