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