public bool verify(byte[] sig)
		{			
			cs.Close();
			System.Security.Cryptography.DSACryptoServiceProvider DSA = new System.Security.Cryptography.DSACryptoServiceProvider();
			DSA.ImportParameters(DSAKeyInfo);
			System.Security.Cryptography.DSASignatureDeformatter DSADeformatter = new System.Security.Cryptography.DSASignatureDeformatter(DSA);
			DSADeformatter.SetHashAlgorithm("SHA1");

			long i=0;
			long j=0;
			byte[] tmp;

			//This makes sure sig is always 40 bytes?
			if(sig[0]==0 && sig[1]==0 && sig[2]==0)
			{
				long i1 = (sig[i++]<<24)&0xff000000;
				long i2 = (sig[i++]<<16)&0x00ff0000;
				long i3 = (sig[i++]<<8)&0x0000ff00;
				long i4 = (sig[i++])&0x000000ff;
				j = i1 | i2 | i3 | i4;

				i+=j;

				i1 = (sig[i++]<<24)&0xff000000;
				i2 = (sig[i++]<<16)&0x00ff0000;
				i3 = (sig[i++]<<8)&0x0000ff00;
				i4 = (sig[i++])&0x000000ff;
				j = i1 | i2 | i3 | i4;

				tmp=new byte[j]; 
				Array.Copy(sig, i, tmp, 0, j); sig=tmp;
			}
			bool res = DSADeformatter.VerifySignature(sha1, sig);
			return res;
		}
Пример #2
0
        public bool verify(byte[] sig)
        {
            cs.Close();
            System.Security.Cryptography.DSACryptoServiceProvider DSA = new System.Security.Cryptography.DSACryptoServiceProvider();
            DSA.ImportParameters(DSAKeyInfo);
            System.Security.Cryptography.DSASignatureDeformatter DSADeformatter = new System.Security.Cryptography.DSASignatureDeformatter(DSA);
            DSADeformatter.SetHashAlgorithm("SHA1");

            long i = 0;
            long j = 0;

            byte[] tmp;

            //This makes sure sig is always 40 bytes?
            if (sig[0] == 0 && sig[1] == 0 && sig[2] == 0)
            {
                long i1 = (sig[i++] << 24) & 0xff000000;
                long i2 = (sig[i++] << 16) & 0x00ff0000;
                long i3 = (sig[i++] << 8) & 0x0000ff00;
                long i4 = (sig[i++]) & 0x000000ff;
                j = i1 | i2 | i3 | i4;

                i += j;

                i1 = (sig[i++] << 24) & 0xff000000;
                i2 = (sig[i++] << 16) & 0x00ff0000;
                i3 = (sig[i++] << 8) & 0x0000ff00;
                i4 = (sig[i++]) & 0x000000ff;
                j  = i1 | i2 | i3 | i4;

                tmp = new byte[j];
                Array.Copy(sig, i, tmp, 0, j);
                sig = tmp;
            }
            bool res = DSADeformatter.VerifySignature(sha1, sig);

            return(res);
        }
Пример #3
0
        public bool verify(byte[] sig)
        {
            cs.Close();
            System.Security.Cryptography.DSACryptoServiceProvider DSA = new System.Security.Cryptography.DSACryptoServiceProvider();
            DSA.ImportParameters(DSAKeyInfo);
            System.Security.Cryptography.DSASignatureDeformatter DSADeformatter = new System.Security.Cryptography.DSASignatureDeformatter(DSA);
            DSADeformatter.SetHashAlgorithm("SHA1");

            int i=0;
            int j=0;
            byte[] tmp;

            if(sig[0]==0 && sig[1]==0 && sig[2]==0)
            {
                j=(int)((sig[i++]<<24)&0xff000000)|(byte)((sig[i++]<<16)&0x00ff0000)|(byte)
                    ((sig[i++]<<8)&0x0000ff00)|(byte)((sig[i++])&0x000000ff);
                i+=j;
                j=(int)((sig[i++]<<24)&0xff000000)|(byte)((sig[i++]<<16)&0x00ff0000)|(byte)
                    ((sig[i++]<<8)&0x0000ff00)|(byte)((sig[i++])&0x000000ff);
                tmp=new byte[j];
                Array.Copy(sig, i, tmp, 0, j); sig=tmp;
            }

            //			// ASN.1
            //			int frst=((sig[0]&0x80)!=0?1:0);
            //			int scnd=((sig[20]&0x80)!=0?1:0);
            //			//System.out.println("frst: "+frst+", scnd: "+scnd);
            //
            //			int length=sig.Length+6+frst+scnd;
            //			tmp=new byte[length];
            //			tmp[0]=(byte)0x30; tmp[1]=(byte)0x2c;
            //			tmp[1]+=(byte)frst; tmp[1]+=(byte)scnd;
            //			tmp[2]=(byte)0x02; tmp[3]=(byte)0x14;
            //			tmp[3]+=(byte)frst;
            //			Array.Copy(sig, 0, tmp, 4+frst, 20);
            //			tmp[4+tmp[3]]=(byte)0x02; tmp[5+tmp[3]]=(byte)0x14;
            //			tmp[5+tmp[3]]+=(byte)scnd;
            //			Array.Copy(sig, 20, tmp, 6+tmp[3]+scnd, 20);
            //			sig=tmp;

            /*
                tmp=new byte[sig.length+6];
                tmp[0]=(byte)0x30; tmp[1]=(byte)0x2c;
                tmp[2]=(byte)0x02; tmp[3]=(byte)0x14;
                System.arraycopy(sig, 0, tmp, 4, 20);
                tmp[24]=(byte)0x02; tmp[25]=(byte)0x14;
                System.arraycopy(sig, 20, tmp, 26, 20); sig=tmp;
            */
            //return signature.verify(sig);

            //Console.WriteLine("Sig Length = "+sig.Length);
            //bool res = DSADeformatter.VerifySignature(sha1, Util.FixDsaSig2(sig));
            bool res = DSADeformatter.VerifySignature(sha1, sig);
            return res;
        }