Good day
I am having serious issues trying to assign a private key due to this error.
System.Security.Cryptography.CryptographicException: Keyset does not exist
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
var col = store.Certificates.Find(X509FindType.FindBySerialNumber, "00873476DC47C5BB614EA96F2A9CE744A6", false);
var cert = col[0];
var xmlUnSignedSaml = new XmlDocument();
xmlUnSignedSaml.LoadXml(assertion);
xmlUnSignedSaml.PreserveWhitespace = true;
SignedXml signedXml = new SignedXml(xmlUnSignedSaml);
signedXml.SigningKey = cert.PrivateKey; //<<<--- Exception thrown.
I have verified the following:
I have checked the answers at the following pages, but absolutely none of them worked for me:
I am running the application from within Visual Studio, and at the code segment above, it throws the exception trying to set the SignedXml's SigningKey
What else can I do to get this up and running? (Afterthought, I have also tried the "Everyone" permission on the cert and folder - even that threw the same exception)
I have solved my issue using the following steps:
ctrl+shift+B
.Main(string args[])
Method Because I am lazy and don't want to do it through the console: args = new string[] { "My", "LocalMachine", "-t", THUMBPRINT_OBTAINED_IN_MMC, "-a" };
I changed the permissions on the key itself, and my application started working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With