1

I have imported System.Security.Cryptography.Cng using NuGet and can instantiate the RSACng class... however, the methods ExportRSAPrivateKey (and ImportRSAPrivateKey) are not there.

I am using version 5.0.0 (latest stable)

According to the documentation these functions should be available.

Any help?

Brian Rice
  • 3,107
  • 1
  • 35
  • 53
  • For exporting, it looks like you might need to enable it on a per key basis: https://stackoverflow.com/a/48647314/569976 – neubert Feb 03 '21 at 12:26
  • Double check that you're not working in a .NET Standard 2.0 library (those methods don't exist in the .NET Standard versions of the class). After that: does the method appear if you cast it to the RSA base class (if yes, that'd be super weird, but very good to know)? – bartonjs Feb 03 '21 at 17:24
  • @bartonjs I was certain that I was using .Net Core... but double checked and sure enough I was using .Net Standard 2.0... switching to .Net Core 3.1 fixed the problem... please add this as an answer if you like. – Brian Rice Feb 04 '21 at 05:31

1 Answers1

2

Those methods were added in .NET Core 3.0. They're available for compile targets .NET Core 3.0, .NET Core 3.1, .NET 5, any versions that succeed .NET 5, and .NET Standard 2.1.

.NET Standard 2.0 is a common target for libraries because it provides a common targeting point for both .NET Framework and .NET Core / .NET. Since the methods aren't available in .NET Framework they aren't in .NET Standard 2.0.

Double check that your library is set to compile against an appropriate target.

bartonjs
  • 30,352
  • 2
  • 71
  • 111