00001 using System;
00002 using System.IO;
00003 using System.Windows.Forms;
00004 using Tamir.SharpSsh.jsch;
00005
00006
00007
00008
00009
00010
00011
00012
00013 namespace sharpSshTest.jsch_samples
00014 {
00018 public class AES
00019 {
00020 public static void RunExample(String[] arg)
00021 {
00022 try
00023 {
00024
00025 JSch jsch=new JSch();
00026
00027
00028 Console.WriteLine("Please enter the user and host info at the popup window...");
00029 String host = InputForm.GetUserInput
00030 ("Enter username@hostname",
00031 Environment.UserName+"@localhost");
00032 String user=host.Substring(0, host.IndexOf('@'));
00033 host=host.Substring(host.IndexOf('@')+1);
00034
00035
00036 Session session=jsch.getSession(user, host, 22);
00037
00038
00039 UserInfo ui=new MyUserInfo();
00040 session.setUserInfo(ui);
00041
00042
00043 System.Collections.Hashtable config=new System.Collections.Hashtable();
00044 config.Add("cipher.s2c", "aes128-cbc,3des-cbc");
00045 config.Add("cipher.c2s", "aes128-cbc,3des-cbc");
00046 session.setConfig(config);
00047
00048
00049 session.connect();
00050
00051
00052 Channel channel=session.openChannel("shell");
00053
00054
00055 channel.setInputStream(Console.OpenStandardInput());
00056 channel.setOutputStream(Console.OpenStandardOutput());
00057
00058
00059 channel.connect();
00060
00061 Console.WriteLine("-- Shell channel is connected using the {0} cipher",
00062 session.getCipher());
00063
00064
00065 while(!channel.isClosed())
00066 {
00067 System.Threading.Thread.Sleep(500);
00068 }
00069
00070
00071 channel.disconnect();
00072 session.disconnect();
00073
00074 }
00075 catch(Exception e)
00076 {
00077 Console.WriteLine(e.Message);
00078 }
00079 }
00080
00084 public class MyUserInfo : UserInfo
00085 {
00089 private String passwd;
00090
00094 public String getPassword(){ return passwd; }
00095
00099 public bool promptYesNo(String str)
00100 {
00101 return InputForm.PromptYesNo(str);
00102 }
00103
00107 public String getPassphrase(){ return null; }
00108
00112 public bool promptPassphrase(String message){ return true; }
00113
00117 public bool promptPassword(String message)
00118 {
00119 passwd=InputForm.GetUserInput(message, true);
00120 return true;
00121 }
00122
00126 public void showMessage(String message)
00127 {
00128 InputForm.ShowMessage(message);
00129 }
00130 }
00131 }
00132 }