Example #1
0
        public void MD5ComparisonTest()
        {
            CloudStorageAccount.UseV1MD5 = false;

            try
            {
                using (MD5Wrapper nativeHash = new MD5Wrapper())
                {
                    nativeHash.UpdateHash(data, 0, data.Length);
                    string nativeResult = nativeHash.ComputeHash();

                    MD5 hash = MD5.Create();
                    hash.TransformBlock(data, 0, data.Length, null, 0);
                    hash.TransformFinalBlock(new byte[0], 0, 0);
                    byte[] bytes  = hash.Hash;
                    string result = Convert.ToBase64String(bytes);

                    Assert.AreEqual(nativeResult, result);
                }
            }
            finally
            {
                CloudStorageAccount.UseV1MD5 = true;
            }
        }
Example #2
0
        public void MD5BigDataTest()
        {
            byte[] data = new byte[10000];
            for (int i = 1; i < 10000; i++)
            {
                data[i] = 1;
            }

            using (MD5Wrapper nativeHash = new MD5Wrapper())
            {
                MD5 hash = MD5.Create();
                for (int i = 0; i < 999; i++)
                {
                    int index = 10 * i;
                    nativeHash.UpdateHash(data, 0, 10);
                    hash.TransformBlock(data, 0, 10, null, 0);
                }
                string nativeResult = nativeHash.ComputeHash();

                hash.TransformFinalBlock(new byte[0], 0, 0);
                var    varResult = hash.Hash;
                String result    = Convert.ToBase64String(varResult);

                Assert.AreEqual(nativeResult, result);
            }
        }
Example #3
0
        public void MD5SingleByteTest()
        {
            using (MD5Wrapper nativeHash = new MD5Wrapper())
            {
                nativeHash.UpdateHash(data, 3, 2);
                string nativeResult = nativeHash.ComputeHash();

                MD5 hash = MD5.Create();
                hash.TransformBlock(data, 3, 2, null, 0);
                hash.TransformFinalBlock(new byte[0], 0, 0);
                var    bytes  = hash.Hash;
                string result = Convert.ToBase64String(bytes);

                Assert.AreEqual(nativeResult, result);
            }
        }
Example #4
0
        public void MD5LastByteTest()
        {
            using (MD5Wrapper nativeHash = new MD5Wrapper())
            {
                nativeHash.UpdateHash(data, 8, 1);
                string nativeResult = nativeHash.ComputeHash();


                MD5 hash = MD5.Create();
                hash.ComputeHash(data, 8, 1);
                var    varResult = hash.Hash;
                string result    = Convert.ToBase64String(varResult);

                Assert.AreEqual(nativeResult, result);
            }
        }
Example #5
0
        public void MD5V1ComparisonTest()
        {
            using (MD5Wrapper nativeHash = new MD5Wrapper())
            {
                nativeHash.UpdateHash(data, 0, data.Length);
                string nativeResult = nativeHash.ComputeHash();

                MD5 hash = MD5.Create();
                hash.TransformBlock(data, 0, data.Length, null, 0);
                hash.TransformFinalBlock(new byte[0], 0, 0);
                byte[] bytes  = hash.Hash;
                string result = Convert.ToBase64String(bytes);

                Assert.AreEqual(nativeResult, result);
            }
        }
Example #6
0
        public void MD5EmptyArrayTest()
        {
            byte[] data = new byte[] { };
            using (MD5Wrapper nativeHash = new MD5Wrapper())
            {
                nativeHash.UpdateHash(data, 0, data.Length);
                string nativeResult = nativeHash.ComputeHash();


                MD5 hash = MD5.Create();
                hash.ComputeHash(data, 0, data.Length);
                var    varResult = hash.Hash;
                string result    = Convert.ToBase64String(varResult);

                Assert.AreEqual(nativeResult, result);
            }
        }
Example #7
0
        public void MD5LastByteTest()
        {
            CloudStorageAccount.UseV1MD5 = false;
            try
            {
                using (MD5Wrapper nativeHash = new MD5Wrapper())
                {
                    nativeHash.UpdateHash(data, 8, 1);
                    string nativeResult = nativeHash.ComputeHash();


                    MD5 hash = MD5.Create();
                    hash.ComputeHash(data, 8, 1);
                    byte[] varResult = hash.Hash;
                    string result    = Convert.ToBase64String(varResult);

                    Assert.AreEqual(nativeResult, result);
                }
            }
            finally
            {
                CloudStorageAccount.UseV1MD5 = true;
            }
        }