00001 using System;
00002
00003 namespace Tamir.SharpSsh.jsch
00004 {
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 public class HostKey{
00035 private static byte[] sshdss= System.Text.Encoding.Default.GetBytes( "ssh-dss" );
00036 private static byte[] sshrsa= System.Text.Encoding.Default.GetBytes( "ssh-rsa" );
00037
00038 public const int SSHDSS=0;
00039 public const int SSHRSA=1;
00040 public const int UNKNOWN=2;
00041
00042 internal String host;
00043 internal int type;
00044 internal byte[] key;
00045 public HostKey(String host, byte[] key)
00046 {
00047 this.host=host; this.key=key;
00048 if(key[8]=='d'){ this.type=SSHDSS; }
00049 else if(key[8]=='r'){ this.type=SSHRSA; }
00050 else { throw new JSchException("invalid key type");}
00051 }
00052 internal HostKey(String host, int type, byte[] key){
00053 this.host=host; this.type=type; this.key=key;
00054 }
00055 public String getHost(){ return host; }
00056 public String getType(){
00057 if(type==SSHDSS){ return System.Text.Encoding.Default.GetString(sshdss); }
00058 if(type==SSHRSA){ return System.Text.Encoding.Default.GetString(sshrsa);}
00059 return "UNKNOWN";
00060 }
00061 public String getKey(){
00062 return Convert.ToBase64String(key, 0, key.Length);
00063 }
00064 public String getFingerPrint(JSch jsch){
00065 HASH hash=null;
00066 try{
00067 hash=(HASH)Activator.CreateInstance(Type.GetType(jsch.getConfig("md5")));
00068 }
00069 catch(Exception e){ Console.Error.WriteLine("getFingerPrint: "+e); }
00070 return Util.getFingerPrint(hash, key);
00071 }
00072 }
00073
00074 }