00001 using System;
00002 using Tamir.SharpSsh.jsch;
00003
00004
00005
00006
00007
00008
00009
00010 namespace Tamir.SharpSsh.jsch.examples
00011 {
00019 public class KeyGen
00020 {
00021 public static void Main(params string[] arg)
00022 {
00023 if(arg.Length<3)
00024 {
00025 Console.Error.WriteLine(
00026 "usage: java KeyGen rsa output_keyfile comment\n"+
00027 " java KeyGen dsa output_keyfile comment");
00028 Environment.Exit(-1);
00029 }
00030
00031
00032 String _type=arg[0];
00033 int type=0;
00034 if(_type.Equals("rsa")){type=KeyPair.RSA;}
00035 else if(_type.Equals("dsa")){type=KeyPair.DSA;}
00036 else
00037 {
00038 Console.Error.WriteLine(
00039 "usage: java KeyGen rsa output_keyfile comment\n"+
00040 " java KeyGen dsa output_keyfile comment");
00041 Environment.Exit(-1);
00042 }
00043
00044 String filename=arg[1];
00045
00046 String comment=arg[2];
00047
00048
00049 JSch jsch=new JSch();
00050
00051
00052 String passphrase=InputForm.GetUserInput("Enter passphrase (empty for no passphrase)", true);
00053
00054 try
00055 {
00056
00057 KeyPair kpair=KeyPair.genKeyPair(jsch, type);
00058
00059 kpair.setPassphrase(passphrase);
00060
00061 kpair.writePrivateKey(filename);
00062
00063 kpair.writePublicKey(filename+".pub", comment);
00064
00065 Console.WriteLine("Finger print: "+kpair.getFingerPrint());
00066
00067 kpair.dispose();
00068 }
00069 catch(Exception e)
00070 {
00071 Console.WriteLine(e);
00072 }
00073 Environment.Exit(0);
00074 }
00075 }
00076 }