我正在尝试以自定义操作在本地机器存储中安装证书。证书已安装,但当我使用它查询 AWS 时,出现此错误:
对象仅包含密钥对的公共部分。还必须提供私钥。
安装程序正在运行提升,目标是 Windows Vista。
如果我使用单独的 .exe 安装完全相同的证书,使用完全相同的代码,它可以工作。那么使用 Windows Installer 安装证书有什么不同呢?
编码:
private void InstallCertificate(string certificatePath, string certificatePassword)
{
if (IsAdmin())
{
try
{
X509Certificate2 cert = new X509Certificate2(certificatePath, certificatePassword,
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Add(cert);
store.Close();
}
catch (Exception ex)
{
throw new DataException("Certificate appeared to load successfully but also seems to be null.", ex);
}
}
else
{
throw new Exception("Not enough priviliges to install certificate");
}
}