System.Security.Cryptography.CryptographicException: 'The requested operation is not supported. RRS feed

  • Question

  • I generated a certificate using .NET framework 4.8, after generation of the certificate I try to export the parameters including the private key parameters. I face the exception, the requested operation is not supported in the line exportparameter(true)

    The following is the code sample:

    using (RSA key =  RSA.Create(2048))
                    var request = new CertificateRequest(distinguishedName, key, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
                        new X509KeyUsageExtension(X509KeyUsageFlags.DigitalSignature | X509KeyUsageFlags.KeyCertSign | X509KeyUsageFlags.KeyEncipherment,

                        new X509BasicConstraintsExtension(true, true, 0, false));

    using (var parentCertificate = request.CreateSelfSigned(new DateTimeOffset(DateTime.UtcNow.AddDays(0)),
                        new DateTimeOffset(DateTime.UtcNow.AddYears(30))))

                        var cert = new X509Certificate2(parentCertificate.Export(X509ContentType.Pfx, ""),
                             "",  X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet );
                        RSAKey = cert.GetRSAPrivateKey();
                         param = RSAKey.ExportParameters(true);



    I see the difference between both the certificate is in export policy. Parentcertificate private key has export policy "AllowPlainTextExpot', where as the cert has Export policy "AllowExport".

    Thursday, November 26, 2020 1:30 PM


All replies

  • Hi KiruthikaSE,

    Thank you for posting here.

    I have moved the thread to 'where is the forum for' forum to help you find the correct forum to go ask questions.

    Thank you for posting here.

    Best Regards,

    Xingyu Zhao

    Visual Basic and CLR forum will be migrating to a new home on Microsoft Q&A! (VB.NET and CLR) We invite you to post new questions in the new home on Microsoft Q&A ! For more information, please refer to the sticky post(VB.NET and CLR).

    Friday, November 27, 2020 8:38 AM
  • Hi,

    I suggest asking over at the dedicated .NET Framework Development forum over here:

    (Please don't forget to mark helpful replies as answer, thank you)

    Best regards,

    Blog: https://thesystemcenterblog.com LinkedIn:

    • Proposed as answer by Guido Franzke Friday, November 27, 2020 11:56 AM
    • Marked as answer by Guido Franzke Friday, December 4, 2020 7:00 AM
    Friday, November 27, 2020 8:46 AM