C
C#3mo ago
iHouqLF

Generate RSA keypairs with passphrase for SSH.NET

I need to create a key pair which can be used by the renci.sshnet library to connect to a ssh server (after I would copy the public key). I tried using https://github.com/ShawInnes/SshKeyGenerator, but this library doesn't seem to support passphrases. I also don't want to store the keys in files. I also couldn't get https://github.com/darinkes/SshNet.Keygen to work, which would support passphrases.
18 Replies
Pobiega
Pobiega3mo ago
Where are you gonna store the keys, if not in files?
iHouqLF
iHouqLF3mo ago
In a variable
Pobiega
Pobiega3mo ago
that seems awfully temporary are you gonna be re-generating keys every time the app starts?
iHouqLF
iHouqLF3mo ago
I'm trying to build a program that connects to a ssh server, swaps out a key (~/.ssh/authorized_keys), then stores the key encrypted in a database For that, it has to generate a new key pair
Pobiega
Pobiega3mo ago
var keyInfo = new SshKeyGenerateInfo { Encryption = new SshKeyEncryptionAes256("my passphrase") };
var privateKey = SshKey.Generate(keyInfo);
var publicKey = privateKey.ToPublic();
var fingerprint = privateKey.Fingerprint();

Console.WriteLine($"Fingerprint: {fingerprint}");
var keyInfo = new SshKeyGenerateInfo { Encryption = new SshKeyEncryptionAes256("my passphrase") };
var privateKey = SshKey.Generate(keyInfo);
var publicKey = privateKey.ToPublic();
var fingerprint = privateKey.Fingerprint();

Console.WriteLine($"Fingerprint: {fingerprint}");
this seems fine.. SshNet.Keygen. Its only in pre-release and requires the 2022 version of SshNet, but it seems to work
iHouqLF
iHouqLF3mo ago
thanks, but where can I find the 2022 version of Ssh.net?
No description
Pobiega
Pobiega3mo ago
Just install the keygen and it gives you sshnet transatively
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Pobiega
Pobiega3mo ago
Because the keygen package internally depends on it And seems a little so-so maintained
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Pobiega
Pobiega3mo ago
That screenshot shows sshnet itself, not sshnet.keygen
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
iHouqLF
iHouqLF3mo ago
I'm trying to use a newer version ssh.net but I get this error. It would be important that I can use the newer version of ssh.net Is it somehow possible that I can use both versions? The old version for sshnet.keygen and the new version for connections?
No description
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
iHouqLF
iHouqLF3mo ago
but then my other code doesn't work anymore
MODiX
MODiX3mo ago
Pobiega
var keyInfo = new SshKeyGenerateInfo { Encryption = new SshKeyEncryptionAes256("my passphrase") };
var privateKey = SshKey.Generate(keyInfo);
var publicKey = privateKey.ToPublic();
var fingerprint = privateKey.Fingerprint();

Console.WriteLine($"Fingerprint: {fingerprint}");
var keyInfo = new SshKeyGenerateInfo { Encryption = new SshKeyEncryptionAes256("my passphrase") };
var privateKey = SshKey.Generate(keyInfo);
var publicKey = privateKey.ToPublic();
var fingerprint = privateKey.Fingerprint();

Console.WriteLine($"Fingerprint: {fingerprint}");
React with ❌ to remove this embed.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
iHouqLF
iHouqLF3mo ago
nvm, seems to work now xD Thank you for the help guys