If you want to get an X509Certificate2 with RSACng, try this:
CngKeyCreationParameters cng = new CngKeyCreationParameters
{
KeyUsage = CngKeyUsages.AllUsages,
Provider = new CngProvider("My Crypto Key Storage Provider"),
KeyCreationOptions = CngKeyCreationOptions.MachineKey
};
CngKey cngKey = CngKey.Open("My Key Container");
RSACng rsaKey = new RSACng(cngKey);
X509Certificate2 cert = new X509Certificate2();
var certWithKey = cert.CopyWithPrivateKey(rsaKey);
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.