コード例 #1
0
 internal override bool Parse(byte[] plain)
 {
     try
     {
         if (vendor == VENDOR_FSECURE)
         {
             if (plain[0] != unchecked ((int)(0x30)))
             {
                 // FSecure
                 Buffer buf = new Buffer(plain);
                 buf.GetInt();
                 P_array   = buf.GetMPIntBits();
                 G_array   = buf.GetMPIntBits();
                 Q_array   = buf.GetMPIntBits();
                 pub_array = buf.GetMPIntBits();
                 prv_array = buf.GetMPIntBits();
                 return(true);
             }
             return(false);
         }
         int index  = 0;
         int length = 0;
         if (plain[index] != unchecked ((int)(0x30)))
         {
             return(false);
         }
         index++;
         // SEQUENCE
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         if (plain[index] != unchecked ((int)(0x02)))
         {
             return(false);
         }
         index++;
         // INTEGER
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         P_array = new byte[length];
         System.Array.Copy(plain, index, P_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         Q_array = new byte[length];
         System.Array.Copy(plain, index, Q_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         G_array = new byte[length];
         System.Array.Copy(plain, index, G_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         pub_array = new byte[length];
         System.Array.Copy(plain, index, pub_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         prv_array = new byte[length];
         System.Array.Copy(plain, index, prv_array, 0, length);
         index += length;
     }
     catch (Exception)
     {
         //System.err.println(e);
         //e.printStackTrace();
         return(false);
     }
     return(true);
 }
コード例 #2
0
 internal virtual bool Decrypt_dss()
 {
     try
     {
         byte[] plain;
         if (encrypted)
         {
             if (keytype == OPENSSH)
             {
                 cipher.Init(NSch.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(NSch.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] != unchecked ((int)(0x30)))
         {
             return(false);
         }
         index++;
         // SEQUENCE
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         if (plain[index] != unchecked ((int)(0x02)))
         {
             return(false);
         }
         index++;
         // INTEGER
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         P_array = new byte[length];
         System.Array.Copy(plain, index, P_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         Q_array = new byte[length];
         System.Array.Copy(plain, index, Q_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         G_array = new byte[length];
         System.Array.Copy(plain, index, G_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         pub_array = new byte[length];
         System.Array.Copy(plain, index, pub_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         prv_array = new byte[length];
         System.Array.Copy(plain, index, prv_array, 0, length);
         index += length;
     }
     catch (Exception)
     {
         //System.err.println(e);
         //e.printStackTrace();
         return(false);
     }
     return(true);
 }
コード例 #3
0
 internal virtual 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(NSch.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(NSch.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] != unchecked ((int)(0x30)))
         {
             return(false);
         }
         index++;
         // SEQUENCE
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         if (plain[index] != unchecked ((int)(0x02)))
         {
             return(false);
         }
         index++;
         // INTEGER
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         index += length;
         //System.err.println("int: len="+length);
         //System.err.print(Integer.toHexString(plain[index-1]&0xff)+":");
         //System.err.println("");
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         n_array = new byte[length];
         System.Array.Copy(plain, index, n_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         e_array = new byte[length];
         System.Array.Copy(plain, index, e_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         d_array = new byte[length];
         System.Array.Copy(plain, index, d_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         p_array = new byte[length];
         System.Array.Copy(plain, index, p_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         q_array = new byte[length];
         System.Array.Copy(plain, index, q_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         dmp1_array = new byte[length];
         System.Array.Copy(plain, index, dmp1_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         dmq1_array = new byte[length];
         System.Array.Copy(plain, index, dmq1_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         iqmp_array = new byte[length];
         System.Array.Copy(plain, index, iqmp_array, 0, length);
         index += length;
     }
     catch (Exception)
     {
         //System.err.println(e);
         return(false);
     }
     return(true);
 }
コード例 #4
0
ファイル: IdentityFile.cs プロジェクト: yayanyang/monodevelop
		internal virtual bool Decrypt_dss()
		{
			try
			{
				byte[] plain;
				if (encrypted)
				{
					if (keytype == OPENSSH)
					{
						cipher.Init(NSch.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(NSch.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] != unchecked((int)(0x30)))
				{
					return false;
				}
				index++;
				// SEQUENCE
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				if (plain[index] != unchecked((int)(0x02)))
				{
					return false;
				}
				index++;
				// INTEGER
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				P_array = new byte[length];
				System.Array.Copy(plain, index, P_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				Q_array = new byte[length];
				System.Array.Copy(plain, index, Q_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				G_array = new byte[length];
				System.Array.Copy(plain, index, G_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				pub_array = new byte[length];
				System.Array.Copy(plain, index, pub_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				prv_array = new byte[length];
				System.Array.Copy(plain, index, prv_array, 0, length);
				index += length;
			}
			catch (Exception)
			{
				//System.err.println(e);
				//e.printStackTrace();
				return false;
			}
			return true;
		}
コード例 #5
0
ファイル: IdentityFile.cs プロジェクト: yayanyang/monodevelop
		internal virtual 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(NSch.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(NSch.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] != unchecked((int)(0x30)))
				{
					return false;
				}
				index++;
				// SEQUENCE
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				if (plain[index] != unchecked((int)(0x02)))
				{
					return false;
				}
				index++;
				// INTEGER
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				index += length;
				//System.err.println("int: len="+length);
				//System.err.print(Integer.toHexString(plain[index-1]&0xff)+":");
				//System.err.println("");
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				n_array = new byte[length];
				System.Array.Copy(plain, index, n_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				e_array = new byte[length];
				System.Array.Copy(plain, index, e_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				d_array = new byte[length];
				System.Array.Copy(plain, index, d_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				p_array = new byte[length];
				System.Array.Copy(plain, index, p_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				q_array = new byte[length];
				System.Array.Copy(plain, index, q_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				dmp1_array = new byte[length];
				System.Array.Copy(plain, index, dmp1_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				dmq1_array = new byte[length];
				System.Array.Copy(plain, index, dmq1_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				iqmp_array = new byte[length];
				System.Array.Copy(plain, index, iqmp_array, 0, length);
				index += length;
			}
			catch (Exception)
			{
				//System.err.println(e);
				return false;
			}
			return true;
		}
コード例 #6
0
ファイル: KeyPairRSA.cs プロジェクト: LunarLanding/ngit
		internal override bool Parse(byte[] plain)
		{
			try
			{
				int index = 0;
				int length = 0;
				if (vendor == VENDOR_FSECURE)
				{
					if (plain[index] != unchecked((int)(0x30)))
					{
						// FSecure
						Buffer buf = new Buffer(plain);
						pub_array = buf.GetMPIntBits();
						prv_array = buf.GetMPIntBits();
						n_array = buf.GetMPIntBits();
						byte[] u_array = buf.GetMPIntBits();
						p_array = buf.GetMPIntBits();
						q_array = buf.GetMPIntBits();
						return true;
					}
					return false;
				}
				index++;
				// SEQUENCE
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				if (plain[index] != unchecked((int)(0x02)))
				{
					return false;
				}
				index++;
				// INTEGER
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				index += length;
				//System.err.println("int: len="+length);
				//System.err.print(Integer.toHexString(plain[index-1]&0xff)+":");
				//System.err.println("");
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				n_array = new byte[length];
				System.Array.Copy(plain, index, n_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				pub_array = new byte[length];
				System.Array.Copy(plain, index, pub_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				prv_array = new byte[length];
				System.Array.Copy(plain, index, prv_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				p_array = new byte[length];
				System.Array.Copy(plain, index, p_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				q_array = new byte[length];
				System.Array.Copy(plain, index, q_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				ep_array = new byte[length];
				System.Array.Copy(plain, index, ep_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				eq_array = new byte[length];
				System.Array.Copy(plain, index, eq_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				c_array = new byte[length];
				System.Array.Copy(plain, index, c_array, 0, length);
				index += length;
			}
			catch (Exception)
			{
				//System.err.println(e);
				return false;
			}
			return true;
		}
コード例 #7
0
 internal override bool Parse(byte[] plain)
 {
     try
     {
         int index  = 0;
         int length = 0;
         if (vendor == VENDOR_FSECURE)
         {
             if (plain[index] != unchecked ((int)(0x30)))
             {
                 // FSecure
                 Buffer buf = new Buffer(plain);
                 pub_array = buf.GetMPIntBits();
                 prv_array = buf.GetMPIntBits();
                 n_array   = buf.GetMPIntBits();
                 byte[] u_array = buf.GetMPIntBits();
                 p_array = buf.GetMPIntBits();
                 q_array = buf.GetMPIntBits();
                 return(true);
             }
             return(false);
         }
         index++;
         // SEQUENCE
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         if (plain[index] != unchecked ((int)(0x02)))
         {
             return(false);
         }
         index++;
         // INTEGER
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         index += length;
         //System.err.println("int: len="+length);
         //System.err.print(Integer.toHexString(plain[index-1]&0xff)+":");
         //System.err.println("");
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         n_array = new byte[length];
         System.Array.Copy(plain, index, n_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         pub_array = new byte[length];
         System.Array.Copy(plain, index, pub_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         prv_array = new byte[length];
         System.Array.Copy(plain, index, prv_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         p_array = new byte[length];
         System.Array.Copy(plain, index, p_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         q_array = new byte[length];
         System.Array.Copy(plain, index, q_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         ep_array = new byte[length];
         System.Array.Copy(plain, index, ep_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         eq_array = new byte[length];
         System.Array.Copy(plain, index, eq_array, 0, length);
         index += length;
         index++;
         length = plain[index++] & unchecked ((int)(0xff));
         if ((length & unchecked ((int)(0x80))) != 0)
         {
             int foo = length & unchecked ((int)(0x7f));
             length = 0;
             while (foo-- > 0)
             {
                 length = (length << 8) + (plain[index++] & unchecked ((int)(0xff)));
             }
         }
         c_array = new byte[length];
         System.Array.Copy(plain, index, c_array, 0, length);
         index += length;
     }
     catch (Exception)
     {
         //System.err.println(e);
         return(false);
     }
     return(true);
 }
コード例 #8
0
ファイル: KeyPairDSA.cs プロジェクト: LunarLanding/ngit
		internal override bool Parse(byte[] plain)
		{
			try
			{
				if (vendor == VENDOR_FSECURE)
				{
					if (plain[0] != unchecked((int)(0x30)))
					{
						// FSecure
						Buffer buf = new Buffer(plain);
						buf.GetInt();
						P_array = buf.GetMPIntBits();
						G_array = buf.GetMPIntBits();
						Q_array = buf.GetMPIntBits();
						pub_array = buf.GetMPIntBits();
						prv_array = buf.GetMPIntBits();
						return true;
					}
					return false;
				}
				int index = 0;
				int length = 0;
				if (plain[index] != unchecked((int)(0x30)))
				{
					return false;
				}
				index++;
				// SEQUENCE
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				if (plain[index] != unchecked((int)(0x02)))
				{
					return false;
				}
				index++;
				// INTEGER
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				P_array = new byte[length];
				System.Array.Copy(plain, index, P_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				Q_array = new byte[length];
				System.Array.Copy(plain, index, Q_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				G_array = new byte[length];
				System.Array.Copy(plain, index, G_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				pub_array = new byte[length];
				System.Array.Copy(plain, index, pub_array, 0, length);
				index += length;
				index++;
				length = plain[index++] & unchecked((int)(0xff));
				if ((length & unchecked((int)(0x80))) != 0)
				{
					int foo = length & unchecked((int)(0x7f));
					length = 0;
					while (foo-- > 0)
					{
						length = (length << 8) + (plain[index++] & unchecked((int)(0xff)));
					}
				}
				prv_array = new byte[length];
				System.Array.Copy(plain, index, prv_array, 0, length);
				index += length;
			}
			catch (Exception)
			{
				//System.err.println(e);
				//e.printStackTrace();
				return false;
			}
			return true;
		}