-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CngKey.Export The requested operation is not supported [Windows] #26031
Comments
When you opened the cert from a PFX you didn't specify X509KeyStorageFlags.Exportable. On Linux keys are always exportable, but on Windows and macOS they aren't always. |
Thanks! X509Certificate2 cert = new X509Certificate2("certificate.pfx", "password", X509KeyStorageFlags.Exportable); I searched everywhere, but didn't find where the issue is. Error message isn't informative and I decided that isn't implemented on windows. |
I have created a self signed RSA certificate and stored the Private key as .pfx file. Then from my .net core 3.1 code i'm trying to instantiate the X509Certificate2 object with the .pfx file. The X509Certificate2 instance is created successfully but from ExportParameters(true) i'm getting the same error though i have set the X509KeyStorageFlags.Exportable. please help me. X509Certificate2 certificate2 = new X509Certificate2(privateKeyData, _privateKeyPwd, X509KeyStorageFlags.Exportable); Exception: |
I'm experiencing the same issue as @ajitsamanta @bartonjs Any updates on how this is supposed to work? |
Exportable ends up meaning two different things depending on if the key got loaded into Windows CAPI or Windows CNG. For CAPI it means ... exportable -- ExportParameters will work, and exporting as a PFX will work. For CNG it ends up meaning "exportable if encrypted", so PFX export works, and ExportEncryptedPkcs8PrivateKey works... but ExportParameters and ExportPkcs8PrivateKey do not. One work-around is to do something like using (RSA tmp = RSA.Create())
using (RSA key = cert.GetRSAPrivateKey())
{
PbeParameters pbeParameters = ...;
tmp.ImportPkcs8PrivateKey(key.ExportPkcs8PrivateKey(pwd, pbeParameters), pwd);
return tmp.ExportParameters(true);
} We -could- do something like that in the platform when we get an error, but we've thus far resisted doing it. What's the scenario that requires you to use ExportParameters(true)? |
@bartonjs Facing the same error I was on Framework not Core. But my scenario is extract from Windows Credential Store certificate and its private key in PEM format to use it as Client Certificate in GRPC Channel. |
Can't get RSAParameters on Windows.
Code to reproduce:
on Windows 10/8.1 returns:
on Ubuntu 16.04
Additional info:
The text was updated successfully, but these errors were encountered: