场景见如下代码,证书来自 pem 格式的证书文件,需求将证书中的私钥赋值给 SecurityKey 类型的 TokenDecryptionKey,请问如何实现?
services.AddAuthentication()
.AddJwtBearer(
options =>
{
var cert = X509Certificate2.CreateFromPemFile("cnblogs.com.crt", "cnblogs.com.key");
options.TokenValidationParameters.TokenDecryptionKey = ?;
});
通过下面的代码解决了
services.AddAuthentication()
.AddJwtBearer(
options =>
{
var cert = X509Certificate2.CreateFromPemFile("cnblogs.com.crt", "cnblogs.com.key");
options.TokenValidationParameters.TokenDecryptionKey =
new X509SecurityKey(cert);
});