DataProtection compatilibity net framework和net core invalid payload exception

时间:2018-04-27 14:00:21

标签: c# asp.net asp.net-core

我有两个项目,一个使用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));

然后我得到无效的有效负载异常。

Github Repostiroy

0 个答案:

没有答案