我有两个项目,一个使用net core,另一个使用net framework。
数据保护密钥的份额,如本link中所述。
.netFramework
public override void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection()
.SetApplicationName("company")
.PersistKeysToFileSystem(new DirectoryInfo("c:\\keys"))
.ProtectKeysWithDpapi();
}
//hello protected in net framework.
var helloProtected = MachineKey.Protect(Encoding.UTF8.GetBytes("hello"),
"testprotector");
var base64HelloProtected = Convert.ToBase64String(helloProtected);
.netCore
public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection()
.SetApplicationName("company")
.PersistKeysToFileSystem(new DirectoryInfo("c:\\keys"))
.ProtectKeysWithDpapi();
}
var bs64msg = //Here i put the protected payload from net framework.
var msgUnprotected = _provider.CreateProtector("testprotector")
.Unprotect(Convert.FromBase64String(bs64msg));
然后我得到无效的有效负载异常。