Why isn't the GenerateKey method available for my ECDiffieHellmanCng object?

Russ Beech 41 Reputation points
2022-01-06T18:07:37.623+00:00

Documentation for the ECDiffieHellmanCng class shows a GenerateKey() method, but this method is not found/recognized in my project (Visual Studio 2019). Any thoughts on how I can get to this method?

Russ

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,364 questions
0 comments No comments
{count} votes

4 additional answers

Sort by: Most helpful
  1. AgaveJoe 26,161 Reputation points
    2022-01-06T18:52:54.57+00:00

    The GenerateKey method is a member of the ECDiffieHellmanCng instance.

        public static void Main(string[] args)
        {
            ECDiffieHellmanCng test = new ECDiffieHellmanCng();
            test.GenerateKey(new ECCurve());
        }
    

    Share your code if need further assistance.

    0 comments No comments

  2. Russ Beech 41 Reputation points
    2022-01-06T19:06:27.697+00:00

    Yes, but it is not available for mine. Does not show up with Intellisense; if typed in completely is underlined in red and generates a Build error. It just isn't available (obviously, it is available to you). Wondering why I don't have it?

    Russ

    162982-capture.jpg

    (I realize a key pair is generated when the instance is created, but I'd like to be able generate a new pair when desired.)

    Russ

    0 comments No comments

  3. Russ Beech 41 Reputation points
    2022-01-06T19:32:44.213+00:00

    Guys, thanks for your input. I think the .net version is the problem. I noticed that the online documentation shows .net 6 for the ECDiffieHellmanCng class. While some of it seems to work with Visual Studio 2019 and .net 4, it appears that I need something newer to use the GenerateKey method. And, I see that I have to upgrade to Visual Studio 2022 in order to use .net 6. The install is underway, will know in a while if that fixes it.

    Russ

    0 comments No comments

  4. Russ Beech 41 Reputation points
    2022-01-06T20:43:44.773+00:00

    Viorel-1,

    Guess I should have tried 4.8 before upgrading to VS2022 (which I can't seem to get to give me .net 6 as an option) - turns out .net 4.8 gives me the GenerateKey() method, even with VS2019.

    0 comments No comments