I have application and I have to use a certificate which requires a pin from prompt window.
I have following code.
SecureString password = GetPassword();
X509Certificate2 certificate = GetCertificate();
var cspParameters = new CspParameters(1,
"ProviderName",
"KeyContainerName",
null,
password);
certificate.PrivateKey = new RSACryptoServiceProvider(cspParameters);
Everything works fine in console application but when I run that code in windows service or console application started from task scheduler then application freezes on that line.
certificate.PrivateKey = new RSACryptoServiceProvider(cspParameters);
No exceptions, no progress.
I'm running windows service with the same credentials as an application.
Windows 10 / Windows Server 2012
Do you have any ideas what is wrong?