I use .NET Core 2.2 on Linux AND Windows, I do not want to use the stores. I try to add permissions to IIS or Everyone for test on "C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys" it does not work.. The file is created and I can open it ! But why my program can't do it ?
X509KeyStorageFlags flags = X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable;
X509Certificate2 cert = new X509Certificate2(rawCert, "myPassword", flags);
var pk = cert.GetRSAPrivateKey(); // Exception
I get this exception :
Internal.Cryptography.CryptoThrowHelper.WindowsCryptographicException HResult=0x80090016 Message=keyset does not exist
Source=System.Security.Cryptography.Csp Arborescence des appels de procédure : at Internal.NativeCrypto.CapiHelper.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer) at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeProvHandle() at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeKeyHandle() at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 keySize, CspParameters parameters, Boolean useDefaultKeySize) at System.Security.Cryptography.RSACryptoServiceProvider..ctor(CspParameters parameters) at Internal.Cryptography.Pal.CertificatePal.<>c.b__66_0(CspParameters csp) at Internal.Cryptography.Pal.CertificatePal.GetPrivateKey[T](Func2 createCsp, Func
2 createCng) at Internal.Cryptography.Pal.CertificatePal.GetRSAPrivateKey() at Internal.Cryptography.Pal.CertificateExtensionsCommon.GetPrivateKey[T](X509Certificate2 certificate, Predicate`1 matchesConstraints) at System.Security.Cryptography.X509Certificates.RSACertificateExtensions.GetRSAPrivateKey(X509Certificate2 certificate) at ConsoleTest.Program.Main(String[] args) in ...
User contributions licensed under CC BY-SA 3.0