RSAVP1() public static method

public static RSAVP1 ( RSA rsa, byte s ) : byte[]
rsa System.Security.Cryptography.RSA
s byte
return byte[]
Ejemplo n.º 1
0
        public static bool Verify_v15(RSA rsa, HashAlgorithm hash, byte[] hashValue, byte[] signature, bool tryNonStandardEncoding)
        {
            int num = rsa.KeySize >> 3;

            byte[] s      = PKCS1.OS2IP(signature);
            byte[] x      = PKCS1.RSAVP1(rsa, s);
            byte[] array  = PKCS1.I2OSP(x, num);
            byte[] array2 = PKCS1.Encode_v15(hash, hashValue, num);
            bool   flag   = PKCS1.Compare(array2, array);

            if (flag || !tryNonStandardEncoding)
            {
                return(flag);
            }
            if (array[0] != 0 || array[1] != 1)
            {
                return(false);
            }
            int i;

            for (i = 2; i < array.Length - hashValue.Length - 1; i++)
            {
                if (array[i] != 255)
                {
                    return(false);
                }
            }
            if (array[i++] != 0)
            {
                return(false);
            }
            byte[] array3 = new byte[hashValue.Length];
            Buffer.BlockCopy(array, i, array3, 0, array3.Length);
            return(PKCS1.Compare(array3, hashValue));
        }
Ejemplo n.º 2
0
        public static bool Verify_v15(
            RSA rsa,
            HashAlgorithm hash,
            byte[] hashValue,
            byte[] signature,
            bool tryNonStandardEncoding)
        {
            int num = rsa.KeySize >> 3;

            byte[] s      = PKCS1.OS2IP(signature);
            byte[] array2 = PKCS1.I2OSP(PKCS1.RSAVP1(rsa, s), num);
            bool   flag   = PKCS1.Compare(PKCS1.Encode_v15(hash, hashValue, num), array2);

            if (flag || !tryNonStandardEncoding)
            {
                return(flag);
            }
            if (array2[0] != (byte)0 || array2[1] != (byte)1)
            {
                return(false);
            }
            int index1;

            for (index1 = 2; index1 < array2.Length - hashValue.Length - 1; ++index1)
            {
                if (array2[index1] != byte.MaxValue)
                {
                    return(false);
                }
            }
            byte[] numArray  = array2;
            int    index2    = index1;
            int    srcOffset = index2 + 1;

            if (numArray[index2] != (byte)0)
            {
                return(false);
            }
            byte[] array1 = new byte[hashValue.Length];
            Buffer.BlockCopy((Array)array2, srcOffset, (Array)array1, 0, array1.Length);
            return(PKCS1.Compare(array1, hashValue));
        }