📄 identityfile.cs
字号:
foo=Q_array;
for(i=0; i<foo.Length; i++){
System.out.print(Integer.toHexString(foo[i]&0xff)+":");
}
System.out.println("");
System.out.print("G ");
foo=G_array;
for(i=0; i<foo.Length; i++){
System.out.print(Integer.toHexString(foo[i]&0xff)+":");
}
System.out.println("");
*/
try
{
Type t=Type.GetType(jsch.getConfig("signature.dss"));
SignatureDSA dsa=(SignatureDSA)(Activator.CreateInstance(t));
dsa.init();
dsa.setPrvKey(prv_array, P_array, Q_array, G_array);
/*
byte[] goo=new byte[4];
goo[0]=(byte)(session.getSessionId().Length>>>24);
goo[1]=(byte)(session.getSessionId().Length>>>16);
goo[2]=(byte)(session.getSessionId().Length>>>8);
goo[3]=(byte)(session.getSessionId().Length);
dsa.update(goo);
dsa.update(session.getSessionId());
*/
dsa.update(data);
byte[] sig = dsa.sign();
Buffer buf=new Buffer("ssh-dss".Length+4+
sig.Length+4);
buf.putString( System.Text.Encoding.Default.GetBytes( "ssh-dss" ) );
buf.putString(sig);
return buf.buffer;
}
catch(Exception e)
{
Console.WriteLine("e "+e);
}
return null;
}
public bool decrypt()
{
if(type==RSA) return decrypt_rsa();
return decrypt_dss();
}
bool decrypt_rsa()
{
// byte[] p_array;
// byte[] q_array;
// byte[] dmp1_array;
// byte[] dmq1_array;
// byte[] iqmp_array;
try
{
byte[] plain;
if(encrypted)
{
if(keytype==OPENSSH)
{
cipher.init(Cipher.DECRYPT_MODE, key, iv);
plain=new byte[encoded_data.Length];
cipher.update(encoded_data, 0, encoded_data.Length, plain, 0);
}
else if(keytype==FSECURE)
{
for(int i=0; i<iv.Length; i++)iv[i]=0;
cipher.init(Cipher.DECRYPT_MODE, key, iv);
plain=new byte[encoded_data.Length];
cipher.update(encoded_data, 0, encoded_data.Length, plain, 0);
}
else
{
return false;
}
}
else
{
if(n_array!=null) return true;
plain=encoded_data;
}
if(keytype==FSECURE)
{ // FSecure
Buffer buf=new Buffer(plain);
int foo=buf.getInt();
if(plain.Length!=foo+4)
{
return false;
}
e_array=buf.getMPIntBits();
d_array=buf.getMPIntBits();
n_array=buf.getMPIntBits();
byte[] u_array=buf.getMPIntBits();
p_array=buf.getMPIntBits();
q_array=buf.getMPIntBits();
return true;
}
int index=0;
int Length=0;
if(plain[index]!=0x30)return false;
index++; // SEQUENCE
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
if(plain[index]!=0x02)return false;
index++; // INTEGER
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
index+=Length;
//System.out.println("int: len="+Length);
//System.out.print(Integer.toHexString(plain[index-1]&0xff)+":");
//System.out.println("");
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
n_array=new byte[Length];
Array.Copy(plain, index, n_array, 0, Length);
index+=Length;
/*
System.out.println("int: N len="+Length);
for(int i=0; i<n_array.Length; i++){
System.out.print(Integer.toHexString(n_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
e_array=new byte[Length];
Array.Copy(plain, index, e_array, 0, Length);
index+=Length;
/*
System.out.println("int: E len="+Length);
for(int i=0; i<e_array.Length; i++){
System.out.print(Integer.toHexString(e_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
d_array=new byte[Length];
Array.Copy(plain, index, d_array, 0, Length);
index+=Length;
/*
System.out.println("int: D len="+Length);
for(int i=0; i<d_array.Length; i++){
System.out.print(Integer.toHexString(d_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
p_array=new byte[Length];
Array.Copy(plain, index, p_array, 0, Length);
index+=Length;
/*
System.out.println("int: P len="+Length);
for(int i=0; i<p_array.Length; i++){
System.out.print(Integer.toHexString(p_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
q_array=new byte[Length];
Array.Copy(plain, index, q_array, 0, Length);
index+=Length;
/*
System.out.println("int: q len="+Length);
for(int i=0; i<q_array.Length; i++){
System.out.print(Integer.toHexString(q_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
dmp1_array=new byte[Length];
Array.Copy(plain, index, dmp1_array, 0, Length);
index+=Length;
/*
System.out.println("int: dmp1 len="+Length);
for(int i=0; i<dmp1_array.Length; i++){
System.out.print(Integer.toHexString(dmp1_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
dmq1_array=new byte[Length];
Array.Copy(plain, index, dmq1_array, 0, Length);
index+=Length;
/*
System.out.println("int: dmq1 len="+Length);
for(int i=0; i<dmq1_array.Length; i++){
System.out.print(Integer.toHexString(dmq1_array[i]&0xff)+":");
}
System.out.println("");
*/
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
iqmp_array=new byte[Length];
Array.Copy(plain, index, iqmp_array, 0, Length);
index+=Length;
/*
System.out.println("int: iqmp len="+Length);
for(int i=0; i<iqmp_array.Length; i++){
System.out.print(Integer.toHexString(iqmp_array[i]&0xff)+":");
}
System.out.println("");
*/
}
catch
{
//System.out.println(e);
return false;
}
return true;
}
bool decrypt_dss()
{
try
{
byte[] plain;
if(encrypted)
{
if(keytype==OPENSSH)
{
cipher.init(Cipher.DECRYPT_MODE, key, iv);
plain=new byte[encoded_data.Length];
cipher.update(encoded_data, 0, encoded_data.Length, plain, 0);
/*
for(int i=0; i<plain.Length; i++){
System.out.print(Integer.toHexString(plain[i]&0xff)+":");
}
System.out.println("");
*/
}
else if(keytype==FSECURE)
{
for(int i=0; i<iv.Length; i++)iv[i]=0;
cipher.init(Cipher.DECRYPT_MODE, key, iv);
plain=new byte[encoded_data.Length];
cipher.update(encoded_data, 0, encoded_data.Length, plain, 0);
}
else
{
return false;
}
}
else
{
if(P_array!=null) return true;
plain=encoded_data;
}
if(keytype==FSECURE)
{ // FSecure
Buffer buf=new Buffer(plain);
int foo=buf.getInt();
if(plain.Length!=foo+4)
{
return false;
}
P_array=buf.getMPIntBits();
G_array=buf.getMPIntBits();
Q_array=buf.getMPIntBits();
pub_array=buf.getMPIntBits();
prv_array=buf.getMPIntBits();
return true;
}
int index=0;
int Length=0;
if(plain[index]!=0x30)return false;
index++; // SEQUENCE
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
if(plain[index]!=0x02)return false;
index++; // INTEGER
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
P_array=new byte[Length];
Array.Copy(plain, index, P_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
Q_array=new byte[Length];
Array.Copy(plain, index, Q_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
G_array=new byte[Length];
Array.Copy(plain, index, G_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
pub_array=new byte[Length];
Array.Copy(plain, index, pub_array, 0, Length);
index+=Length;
index++;
Length=plain[index++]&0xff;
if((Length&0x80)!=0)
{
int foo=Length&0x7f; Length=0;
while(foo-->0){ Length=(Length<<8)+(plain[index++]&0xff); }
}
prv_array=new byte[Length];
Array.Copy(plain, index, prv_array, 0, Length);
index+=Length;
}
catch
{
//System.out.println(e);
//e.printStackTrace();
return false;
}
return true;
}
public bool isEncrypted()
{
return encrypted;
}
public String getName(){return identity;}
private int writeSEQUENCE(byte[] buf, int index, int len)
{
buf[index++]=0x30;
index=writeLength(buf, index, len);
return index;
}
private int writeINTEGER(byte[] buf, int index, byte[] data)
{
buf[index++]=0x02;
index=writeLength(buf, index, data.Length);
Array.Copy(data, 0, buf, index, data.Length);
index+=data.Length;
return index;
}
private int countLength(int i_len)
{
uint len = (uint)i_len;
int i=1;
if(len<=0x7f) return i;
while(len>0)
{
len>>=8;
i++;
}
return i;
}
private int writeLength(byte[] data, int index, int i_len)
{
int len = (int)i_len;
int i=countLength(len)-1;
if(i==0)
{
data[index++]=(byte)len;
return index;
}
data[index++]=(byte)(0x80|i);
int j=index+i;
while(i>0)
{
data[index+i-1]=(byte)(len&0xff);
len>>=8;
i--;
}
return j;
}
private byte a2b(byte c)
{
if('0'<=c&&c<='9') return (byte)(c-'0');
if('a'<=c&&c<='z') return (byte)(c-'a'+10);
return (byte)(c-'A'+10);
}
private byte b2a(byte c)
{
if(0<=c&&c<=9) return (byte)(c+'0');
return (byte)(c-10+'A');
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -