Hi,
I could use some assistance using the data protection APIs.
I have an MVC5 site using forms authentication, and have configured the SystemWeb data protector replacement with the startup class registered below.
public class MyAppDataProtectionStartup : DataProtectionStartup { public override void ConfigureServices(IServiceCollection services) { var path = ConfigurationManager.AppSettings["DataProtectionKeyPath"].ToString(); if (!Path.IsPathRooted(path)) { path = HostingEnvironment.MapPath(path); } services.AddDataProtection() .SetApplicationName("myapp") .PersistKeysToFileSystem(new System.IO.DirectoryInfo(path)) .UseCryptographicAlgorithms(new AuthenticatedEncryptionSettings() { EncryptionAlgorithm = EncryptionAlgorithm.AES_256_GCM, ValidationAlgorithm = ValidationAlgorithm.HMACSHA512 }); } }
This is functional, and I can clearly see that my authentication cookie is being encrypted through the data protection APIs.
I also have an asp.net core app running on subdomain.myapp.com. The auth cookie domain is set properly so that my core app receives the auth cookie on requests. The startup.cs ConfigureServies method has the following code:
public void ConfigureServices(IServiceCollection services) { services.AddDataProtection() .SetApplicationName("myapp") .PersistKeysToFileSystem(new System.IO.DirectoryInfo(samepathasabove)) .UseCryptographicAlgorithms(new AuthenticatedEncryptionSettings() { EncryptionAlgorithm = EncryptionAlgorithm.AES_256_GCM, ValidationAlgorithm = ValidationAlgorithm.HMACSHA512 }); }
On request, I am able to grab the cookie, and use the dataprotecionprovider to decrypt the cookie, but I get an CryptographicException: the provided payload cannot be decrypted because it was not protected with this protection provider.
In debug mode, I have checked the DataProtector application name, protector purpose and secondary purposes, mode, and even the data in the aadtemplate, and in both environments all data is identical.
Is there any other discriminator that I should be looking for? I am at a loss!
Thanks in advance