我正在CentOS上托管我的ASP.NET Core Web应用程序。我需要为Identity Server设置生产签名密钥。该密钥用于JWT令牌签名和验证。
文件:tempkey.rsa
{
"KeyId": "vbWO1QORQrwci26Cd7q59A",
"Parameters": {
"D": "IqOOHtuw10jHnCnrZbzh3TwA40q7KWuby22wl/ooRXn//XJktc8Hwe0JvxD8tvHtk4wfhzkUwiH+zY/cub+kI3oklD9diiWOjFIJcu+k9U9ocXg0ipvrk87rMM3x/u4im9HTYbkNU9Ru6pBdvb8ChAVWR5qOoSVDiFL1Yr8K+sSLix6nm6p0ax2CSf1sJEtNHDRrgI6mSOei97CpiuXpFX/JkwimqvbskcdQY91cgQ9poTWyuolFtFnOx0wSNEG4x1UWVsw85st5JHcU7pN0v1hhQZRcNYBfuZ7uHTFlhbkBip1D191pytSid8C4XTNiLbVPaY1pAqJhDLy6e7bi5Q==",
"DP": "BVqSzlGs02ZFN9/xPug8VDZCxsReFmtd2xwhO8J7/JzGxxbbe9oq78q2blxDH6nY/I2M2DsKbm2BK2xE9ZHTkSuFHYw39OFHH3UZJNw8d3LMq8d2yZlzBTN21uKzVOwYd0zIchfvTIM3laOxW9j7sObOj8Nd/Pawkm2reFsmIzU=",
"DQ": "BvpYLvxVPw7qrCtr6unhawV8ox4obq8WZEK/nu6hqBYxydW+zUJWv0fSYgygP9PYykGuTI+nYxCvm9rqw27uLoGsiEFT23Smzz5kDm0h+OzjJc5Wc+YL9wAI+O/xJ/Bi7uyKu+0eTMvG2Y5WpfYhJv2JZIWQUODHZ9SLDe8X3e8=",
"Exponent": "AQAB",
"InverseQ": "MKg8Pba2dyIsL3pumcR9e24fOZ8NIizJkTsDZoLkU2ccB6fFKfUioglHHL8ZEPKWT3ByJphJZv9JZIxgtCSLhFC1XcNLsWejPvEb6IMX9L1FIM7Ibo05L3tdZGTFsXwU9/3j2gk/ZFPKrnJXV9+6TToEAmxH7HIIPJONsfDBGho=",
"Modulus": "nVpQtZgMHnpz9ZfnJs/sTkA8vqPldPe8IL9JQttcrE3RZKLKd+mrcleLqzrRtBCePHfLZMgoX19ShZeq2t4Ea6Sm+5SkV0l0862OD+ILnzFFqaqvQlra7UnRL2FXwxpp09LqLxoDq8fDXfHGOdMumP2TB6mozFgGWGBY9zlc9ctrDoSvfjsagcsLlp2LhCPAg4yCzyV/+4ADnls7NNnAc2Ba1MGFT5OJpfDggL+FXTMlHwTW8LJ9GsT4FAi5Z7dygLOnWc7zpl+Y9sSUtSNOAQlU+oX9VJQD6ZFbosM8nSHcjvCivpxAzOKn+5I6EQXis+pwne9VVjT27iv/NubG5Q==",
"P": "z53dmREjm+MCchaWsvhPcWVWf7gGezix6KuGzMHa5vhVafrvv2rCy9aHSDWLpxPKb999/2Bw7ExI2b4DTuNkIJTLv/mQEl1PyhtbfLmclPHHbzTM9gnJ3nHrJhpj60/jbinFDkvzV++nqnTKToSgP2TNy5POXWn3FKNHgIxYNwM=",
"Q": "wgXGJTOdv4B1owmtDmxucssRjWQzW0qEOCr/bBjT32ZofRI1HLBjOwnY4qzxmpD00voWLuphZSBUxtF47IZrrr33vNy2jedD3xy00fgBhuG0exxgQagCSTR0+QoccY8jOWYq2B+FsV9umpOEpgtqq67Moe/MkMp8Gg+8fqiLkfc="
}
}
现在,我需要为ASP.NET Core应用生成一个生产密钥。我在Nginx中使用Kestrel。如何生成key.rsa文件并将其用于生产?
我也检查了其他问题。他们正在使用Windows证书存储区来读取证书。我需要使用key.rsa在centos上工作的解决方案。
到目前为止的代码::
// Code skipped for brevity....
#region Add ASP.NET Core Identity Server
// Using ASP.NET Core Identity Server
services.AddIdentityServer()
.AddConfigurationStore<MySQLConfigurationDbContext>()
.AddOperationalStore<MySQLPersistedGrantDbContext>()
.AddAspNetIdentity<Identity.BOL.IdentityUser>()
.AddDeveloperSigningCredential();
#endregion
// Use Authentication
services.AddAuthentication();
}
我不清楚您是否在询问如何生成密钥,或者在生成密钥后如何使用它。我正在猜测第二个问题,因为您已经有了所产生密钥的示例。
您需要摆脱.UseDeveloperSigningCredential()
上的.AddIdentityServer
,并使用其他一些构建器扩展便利方法:
https://identityserver4.readthedocs.io/en/latest/topics/startup.html#refstartupkeymaterial
或者如果您需要更多定制的东西,请使用以下界面:https://identityserver4.readthedocs.io/en/latest/topics/crypto.html
尽管从本质上讲,这些构建器扩展可能就是您所需要的。保持相同版本的代码,并在开发和现场使用不同的关键材料。
这是使用扩展方法的x509重载的示例,但请使用对您的密钥材料有意义的任何一种:
var x509 = new X509Certificate2(
File.ReadAllBytes(somefilename),somepassword);
services.AddIdentityServer(options =>
{
the options I care about
})
.AddSigningCredential(x509)
.AddValidationKey(x509);