Casting private key to RSACryptoServiceProvider not working
问题 I have a X509Certificate2 variable and I'm trying to cast the private key of the variable to a RSACryptoServiceProvider RSACryptoServiceProvider pkey = (RSACryptoServiceProvider)cert.PrivateKey; However I get this exception. System.InvalidCastException: 'Unable to cast object of type 'System.Security.Cryptography.RSACng' to type 'System.Security.Cryptography.RSACryptoServiceProvider'.' It's weird that this happens because other answers in SO suggested the same procedure as mine but I get an