ubi*_*ubi 8 .net c# linux ubuntu asp.net-core-2.0
使用.NET Core 2时,证书文件位于linux中的X509Store哪个位置?
在Windows上,可以从管理控制台certlm.msc或New-SelfSignedCertificatePowerShell 访问证书.使用.NET API,可以在Windows和Linux上通过类似的方式添加证书
using (var store = new X509Store(StoreName.My, StoreLocation.CurrentUser))
{
store.Open(OpenFlags.ReadWrite);
var cert = new X509Certificate2("cert.pfx", "1234");
store.Add(cert);
}
Run Code Online (Sandbox Code Playgroud)
可以通过访问X509Store.Certificates.Find().
但是文件存储在哪里以及如何通过linux工具添加它们?例如,系统管理员将添加证书,应用程序将只读取它们.
@mbican 的答案是正确的。证书放在
~/.dotnet/corefx/cryptography/x509stores/
我不相信没有上下文的这一行答案,也不明白他是如何到达那里的。这就是为什么我想分享我的发现,作为对未来遇到同一问题的所有访问者的答案。
使用 pfx certicicate 文件,您不必将其转换为 pem 或 crt 或其他格式
用 dotnet 存储证书,以便您可以看到文件的放置位置。一个小的 C# 命令行:
using (var store = new X509Store(StoreName.My, StoreLocation.CurrentUser, OpenFlags.ReadWrite))
{
store.Add(new X509Certificate2(
"./thePathToTheCert.pfx", "passwordOfTheCert",
X509KeyStorageFlags.PersistKeySet));
}
Run Code Online (Sandbox Code Playgroud)
这创建了文件夹 ~/.dotnet/corefx/cryptography/x509stores/ 并将证书放入其中。
~/.dotnet/corefx/cryptography/x509stores/my/ThumbPrintOfTheCertificate.pfx
提示:我们曾经StoreLocation.LocalMachine在 windows上使用,但是当我们在 linux 上运行时,没有 LocalMachine 存储,所以我们切换到StoreLocation.CurrentUser. 如果您尝试使用 LocalMachine,您将收到此错误:Unix LocalMachine X509Stores are read-only for all users.
希望这可以帮助某人。
~/.dotnet/corefx/cryptography/x509stores/
| 归档时间: |
|
| 查看次数: |
1638 次 |
| 最近记录: |