Mar*_*dok 5 ssl-certificate .net-core kestrel-http-server
参考Kestrel 文档,是否可以使用 appsettings.json 文件配置 https:
"HttpsInlineCertStore": {
"Url": "https://+:5002",
"Certificate": {
"Subject": "<coma separated multi-line subject name>",
"Store": "Root",
"Location": "LocalMachine"
}
Run Code Online (Sandbox Code Playgroud)
该证书肯定存在,下一个代码返回会找到它:
using (var certStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine))
{
certStore.Open(OpenFlags.ReadOnly);
var certificates = certStore.Certificates.Find(
X509FindType.FindBySubjectDistinguishedName, "<coma separated multi-line subject name>", true);
return certificates .Count > 0 ? certificates [0] : null;;
}
Run Code Online (Sandbox Code Playgroud)
同时,如果通过 X509FindType.FindBySubjectName 搜索证书,它什么也找不到,我相信这就是问题所在,即使微软说 FindBySubjectDistinguishedName 是更具体的搜索。
最后我能够解决这个问题:类似于“CN = name,C = UK,...”,但如果您想 FindBySubjectName,则必须从搜索字符串中删除“CN =”并仅保留名称,以便看起来不像“CN= name ”,而是像“ name ”。
| 归档时间: |
|
| 查看次数: |
3903 次 |
| 最近记录: |