我们正在使用ServiceStack(.netcore)作为我们的Web服务层,在一个尚未上线的开源项目中。我们计划迁移到.netcore2.0。我们于11月17日从https://github.com/ServiceStack/ServiceStack下载了servicestacks的主分支进行测试。但是由于以下异常我们陷入困境,servicestack项目没有启动。
我们对此做了一些研究,发现.Net Core没有toXmlString()和fromXmlString方法。请参阅https://github.com/dotnet/core/issues/874和https://github.com/dotnet/corefx/issues/23686。
需要来自servicestack社区的帮助。
$exception {System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Security.Cryptography.RSA.FromXmlString(String xmlString)
at ServiceStack.RsaUtils.ToPrivateRSAParameters(String privateKeyXml) in F:\ExpressBase\ExpressBase.Core\ServiceStack.Core\ServiceStack.Client\CryptUtils.cs:line 85
at ServiceStack.Auth.JwtAuthProviderReader.set_PrivateKeyXml(String value) in F:\ExpressBase\ExpressBase.Core\ServiceStack.Core\ServiceStack\Auth\JwtAuthProviderReader.cs:line 148
at ExpressBase.ServiceStack.AppHost.Configure(Container container) in F:\ExpressBase\ExpressBase.Core\ExpressBase.ServiceStack\Startup.cs:line 94
at ServiceStack.ServiceStackHost.Init() in F:\ExpressBase\ExpressBase.Core\ServiceStack.Core\ServiceStack\ServiceStackHost.cs:line 200
at ServiceStack.NetCoreAppHostExtensions.UseServiceStack(IApplicationBuilder app, AppHostBase appHost) in F:\ExpressBase\ExpressBase.Core\ServiceStack.Core\ServiceStack\AppHostBase.NetCore.cs:line 224
at ExpressBase.ServiceStack.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in F:\ExpressBase\ExpressBase.Core\ExpressBase.ServiceStack\Startup.cs:line 74} System.PlatformNotSupportedException
这是我们的Startup.cs中生成异常的行。
var jwtprovider = new MyJwtAuthProvider(AppSettings)
{
HashAlgorithm = "RS256",
PrivateKeyXml = EbLiveSettings.PrivateKeyXml,
PublicKeyXml = EbLiveSettings.PublicKeyXml,
RequireSecureConnection = false,
//EncryptPayload = true,
CreatePayloadFilter = (payload, session) =>
{
payload["sub"] = (session as CustomUserSession).UserAuthId;
payload["cid"] = (session as CustomUserSession).CId;
payload["uid"] = (session as CustomUserSession).Uid.ToString();
payload["wc"] = (session as CustomUserSession).WhichConsole;
},
ExpireTokensIn = TimeSpan.FromHours(10),
ExpireRefreshTokensIn = TimeSpan.FromHours(12),
PersistSession = true,
SessionExpiry = TimeSpan.FromHours(12)
};
私有和公钥值从appsettings.json加载到EbLiveSettings。
appsettings.json中的行是
"JwtConfig": {
"PublicKeyXml": "<RSAKeyValue><Modulus>ip...7BfGi98ObWqKnD8o4pv....JQklgmblCs=</Modulus><Exponent>AQAB</Exponent><P></P><Q></Q><DP></DP><DQ></DQ><InverseQ></InverseQ><D></D></RSAKeyValue>",
"PrivateKeyXml": "<RSAKeyValue><Modulus>ip....lss7WqKnD8o4bKTp....IKbK2gaagCQ==</DP><DQ>BKOC....zlic+FQ==</DQ><InverseQ>JeIPWX....A==</InverseQ><D>iHU....cTrKeEGd</D></RSAKeyValue>"
},