Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, my servers uses public keys for authentication. How do I invoke it in the code?

What I have tried:

I tried everything to add the public key file but don't know how to invoke it from the code
Posted
Updated 20-May-16 22:14pm
Comments
[no name] 20-May-16 3:34am    
I tried everything
Most unlikely, but in either case we need much more detail of your problem to be able to help.
RickZeeland 20-May-16 4:44am    
Are you using a certificate, e.g. from Comodo ?
rcfortuna 20-May-16 18:20pm    
If we're going to go to our Linux server from Windows we're using Putty. In Putty we choose SSH->Auth then we enter the Private key for authentication. The private key is generated from puttygen using the following options:

PuTTY-User-Key-File-2: ssh-dss
Encryption: aes256-cbc

I'm sorry for the confusion I guess the correct term is private key instead of public.

I've figured that I'll put my private key path in the IdentifyFile property and my AuthType is Poderosa.ConnectionParam.AuthType.PublicKey. However I got "Wrong key format" when I tried to connect.
phil.o 20-May-16 19:27pm    
Please show your actual code, and describe the format of the key you are providing. The error message states a key-format issue.
Please be precise when you describe your issue. Forcing people to have to guess makes less likely you getting an answer.
rcfortuna 20-May-16 19:51pm    
hi, i've realized that our key is generated using AES256 encryption.

Encryption: aes256-cbc

here's the snippet of my code:

terminalControl1.UserName = username;
terminalControl1.Host = hostname;
terminalControl1.Password = passwordKey; // my password
terminalControl1.IdentifyFile = privateKey; // my private key file eg. c:\keys\mykey.ppk
terminalControl1.AuthType = Poderosa.ConnectionParam.AuthType.PublicKey;


I get it now, it doesn't support AES256 encryption/decryption.

Anyway here's what the key looks like:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "General ssh lvs key username"
AAAAB3NzaC1kc3MAAAEBAJ2RR2CBgCp0CcTA2zVBO/U4+zzHcFuNCYIO2zAnQP1e
1aaz+w/RDDiLQPZzYkBj8+iHy4GYOdU/SypVITypGunkVcGZOuKfMk735cjqACBb
2G9OgWnYNi2ASMGQctEjfe+61pCrEZ4Ivy+ekTXsGb4TKz63MkiHPe5kJZKFzsbO
8vhsSNTXnok5sTBtgqGuSQ6qFJS6Shxk9QS+FcZdoIq+U7OPkKeI+MiC2HmHZndX
Mc63KbuwXUJeHRv8m+bwWhKZCy+xqfKtw1jiLd80pS+iVHDfK6BPIdOlkxh8mj3Q
H4kBMkLlOScVXnDP2IDEa1kLvPH40hHhK/K/rQ68Js0AAAAVAP6lcdk1xxy0pbAV
6IXi3IdOfbAzAAABAFWGnPn10raQE7b7UgBT2sn0MGeXl+cM2aFuWXaJg3o3MZp1
78zbZK/7C40B+uvsAHweaut8xoJTzC+bEq1VTb+CGCVvuVt48oubx3vz55axz04o
V5JOltiZUuWuAUIjfUI5mVIsDjx5eRls+m7CycI2iQdq0OawALm+jRpxiaAZYBsQ
uFrdZacb3hzzfCnLecRufyudtZ7efeW3KZLqlQAy3upYsc5iYmSOkNX1lxhdW7ca
3IhnS/H5kZR4qmCjix9o9ggBoFu0KLdeQsg+70tfsoxl2ooZVi+wXKJPG2rELV/C
eqMLteFrtlzjEELgl6ejFryCCG9FZv8dMj1nMSgAAAEAIZMSFXJzYrYNims/Mh36
Dr6bd2tYLGv6rkm0hfbXzYwWo9OKuSc5F3gWYjnN411kjLh1f1elZVJdhXChxb1k
/+/NwESvrSDoN/6dyIUiRbdbDaOLwbtsai8fwaJOrj06/t4Y05QTz3Bj+kdT1sjg
nIxjfalinRrSNHUTkud+wDS9nbOj24Phn7S50NAaHyZNzOjcszyYfgkL9YPz75mA
CjAtSeAn5vtXswVeA4vqCUzTolDmKGdvLjclcP6RCdxTjU9mLulKhin4yL3XSiGJ
+uc+BsYhOIa+bCzq1gbF9A5h0IiKyfDTE3ZxiDuPZmGYhNJ2CVUIlkRFcPvdaLBK
MA==
---- END SSH2 PUBLIC KEY ----


1 solution

You can get a byte array back from its Base64 representation with the following code:
C#
string base64 = "AAAAB3NzaC1kc3MAAAEBAJ2RR2CBgCp0CcTA2zVBO/U4+zzHcFuNCYIO2zAnQP1e1aaz+w/RDDiLQPZzYkBj8+iHy4GYOdU/SypVITypGunkVcGZOuKfMk735cjqACBb2G9OgWnYNi2ASMGQctEjfe+61pCrEZ4Ivy+ekTXsGb4TKz63MkiHPe5kJZKFzsbO8vhsSNTXnok5sTBtgqGuSQ6qFJS6Shxk9QS+FcZdoIq+U7OPkKeI+MiC2HmHZndXMc63KbuwXUJeHRv8m+bwWhKZCy+xqfKtw1jiLd80pS+iVHDfK6BPIdOlkxh8mj3QH4kBMkLlOScVXnDP2IDEa1kLvPH40hHhK/K/rQ68Js0AAAAVAP6lcdk1xxy0pbAV6IXi3IdOfbAzAAABAFWGnPn10raQE7b7UgBT2sn0MGeXl+cM2aFuWXaJg3o3MZp178zbZK/7C40B+uvsAHweaut8xoJTzC+bEq1VTb+CGCVvuVt48oubx3vz55axz04oV5JOltiZUuWuAUIjfUI5mVIsDjx5eRls+m7CycI2iQdq0OawALm+jRpxiaAZYBsQuFrdZacb3hzzfCnLecRufyudtZ7efeW3KZLqlQAy3upYsc5iYmSOkNX1lxhdW7ca3IhnS/H5kZR4qmCjix9o9ggBoFu0KLdeQsg+70tfsoxl2ooZVi+wXKJPG2rELV/C
eqMLteFrtlzjEELgl6ejFryCCG9FZv8dMj1nMSgAAAEAIZMSFXJzYrYNims/Mh36Dr6bd2tYLGv6rkm0hfbXzYwWo9OKuSc5F3gWYjnN411kjLh1f1elZVJdhXChxb1k/+/NwESvrSDoN/6dyIUiRbdbDaOLwbtsai8fwaJOrj06/t4Y05QTz3Bj+kdT1sjgnIxjfalinRrSNHUTkud+wDS9nbOj24Phn7S50NAaHyZNzOjcszyYfgkL9YPz75mA
CjAtSeAn5vtXswVeA4vqCUzTolDmKGdvLjclcP6RCdxTjU9mLulKhin4yL3XSiGJ+uc+BsYhOIa+bCzq1gbF9A5h0IiKyfDTE3ZxiDuPZmGYhNJ2CVUIlkRFcPvdaLBKMA==";
byte[] key = Convert.FromBase64String(base64);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900