Generate In SshPrivateKey is showing error message like no definition for Generate in SshPrivateKey

0 votes
asked Jun 18, 2019 by shighil K (140 points)

1 Answer

0 votes
answered Jun 18, 2019 by Lukas Pokorny (109,670 points)

Are you targeting .NET Compact Framework? SshPrivateKey.Generate is not available on that platform because - historically - key generation on Windows CE devices was very slow.

However, you can still generate SshPrivateKey keys on .NET CF indirectly via AsymmetricKeyAlgorithm class:

var alg = new AsymmetricKeyAlgorithm();
alg.GenerateKey(AsymmetricKeyAlgorithmId.RSA, 2048);
byte[] keyData = alg.GetPrivateKey().ToBytes();
var key = new SshPrivateKey(keyData);

Sorry for inconvenience. We'll enable SshPrivateKey.Generate on .NET CF as well and let the users decide whether it's fast enough for their needs.

commented Jun 18, 2019 by shighil K (140 points)
Thanks, suggested alternative method  also will help me
commented Jul 1, 2019 by Lukas Pokorny (109,670 points)
We enabled SshPrivateKey.Generate methods on .NET CF in version 2019 R3: