3

I need access to the private key of CNG certificate from .NET 4.6.

In the docs I found extension method GetCngPrivateKey but this method is not available for me in Visual Studio 2015.

Maybe this method was removed from last release of .NET framework.

Any advice what is correct way now for access to the private key of CNG certificate now.

jan
  • 31
  • 2

1 Answers1

3

GetCngPrivateKey was part of the 4.6 preview, but was removed for 4.6 release. It was replaced with GetRSAPrivateKey (and GetECDsaPrivateKey (4.6.1) and GetDSAPrivateKey (4.6.2)).

The Get[Algorithm]{Public|Private}Key methods will return CNG usually (on Windows) and CAPI (CryptoServiceProvider) when they need to. On non-Windows systems (for .NET Core) they use whatever the appropriate backing type is for the system.

The new methods also have the advantage that you almost never need to cast the return type. On 4.6 the RSA base class was enhanced so that all RSA operations could be done without casting. On 4.6.1 ECDSA was enhanced, and on 4.6 DSA was enhanced. The only reason to cast is for interop (like trying to get the name of the persisted key).

bartonjs
  • 30,352
  • 2
  • 71
  • 111