【发布时间】:2017-06-09 17:49:48
【问题描述】:
我有应用程序,我必须使用需要来自提示窗口的密码的证书。
我有以下代码。
SecureString password = GetPassword();
X509Certificate2 certificate = GetCertificate();
var cspParameters = new CspParameters(1,
"ProviderName",
"KeyContainerName",
null,
password);
certificate.PrivateKey = new RSACryptoServiceProvider(cspParameters);
在控制台应用程序中一切正常,但是当我在 Windows 服务中运行该代码或从任务计划程序启动的控制台应用程序时,应用程序会在该行冻结。
certificate.PrivateKey = new RSACryptoServiceProvider(cspParameters);
没有例外,没有进展。
我正在使用与应用程序相同的凭据运行 Windows 服务。
Windows 10 / Windows Server 2012
你有什么想法吗?
【问题讨论】:
-
您可以尝试将服务作为本地系统运行并启动
Interactive Services Detection服务(UI0Detect)。如果有一个 PIN 提示等待它应该带您到特殊桌面 0,您可以在其中输入 PIN。 -
我试过了,但什么也没发生。下周我会再试一次。
标签: c# windows-services private-key x509certificate2