gpt4 book ai didi

c# - 如何在没有密码的情况下将证书安装到个人商店?

转载 作者:太空宇宙 更新时间:2023-11-03 13:38:20 25 4
gpt4 key购买 nike

我对证书之类的东西有点陌生。

我有一个 Web 应用程序,它通过 iframe(它必须是 https,因为应用程序本身也是 https)向在客户端上运行的 .NET 应用程序发送一个 https 请求,该客户端有一个 HttpListener 监听 https://localhost:[port]因此客户端应用程序可以从浏览器点击接收到“现在做某事”。

当我安装客户端应用程序时,我将 *.crt 文件安装到 Root-Store 并将其绑定(bind)到我们的端口:

X509Certificate2 certificateFromCrtFile = new X509Certificate2(X509Certificate2.CreateFromCertFile(crtPath));
X509Store rootStore = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
rootStore.Open(OpenFlags.ReadWrite);
rootStore.Add(certificateFromCrtFile);
rootStore.Close();

string crtThumbprint = certificateFromCrtFile.Thumbprint;
string netshParams = string.Format("http add sslcert ipport=0.0.0.0:[port] certhash={0} appid={{{1}}}", crtThumbprint, Guid.NewGuid());
Utilities.StartProcess("netsh.exe", Environment.SystemDirectory, netshParams, true, true);

现在,在此之前,我还必须在个人商店中安装证书,因为在这种情况下我的“服务器”是同一客户端上的 HttpListener。

好的,所以我可以按以下方式进行:

X509Certificate2 certificateFromPfxFile = new X509Certificate2(pfxPath, "pwd");
X509Store personalStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
personalStore.Open(OpenFlags.ReadWrite);
personalStore.Add(certificateFromPfxFile);
personalStore.Close();

在这种情况下,我必须在代码中以明文形式写入 *.pfx 密码。如果我没理解错的话,使用这个密码你可以很容易地得到私钥,对吧?

最佳答案

当存储在 PFX 中时,私钥使用您的密码加密。因此,当您尝试将其安装到个人商店以表明您对此证书的所有权时,您必须提供密码。这是授权。

受信任的根权限不同,因为您不拥有证书。您只需安装 crt 文件就表明您信任拥有它们的人。

关于c# - 如何在没有密码的情况下将证书安装到个人商店?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32786253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com