コード例 #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;
            }
        }
コード例 #2
0
        public void MD5BigDataTest()
        {
            CloudStorageAccount.UseV1MD5 = false;
            byte[] data = new byte[10000];
            try
            {
                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);
                    byte[] varResult = hash.Hash;
                    String result    = Convert.ToBase64String(varResult);

                    Assert.AreEqual(nativeResult, result);
                }
            }
            finally
            {
                CloudStorageAccount.UseV1MD5 = true;
            }
        }
コード例 #3
0
        internal ChecksumWrapper(bool calcMd5 = true, bool calcCrc64 = true)
        {
            if (calcCrc64)
            {
                this.CRC64 = new Crc64Wrapper();
            }

            if (calcMd5)
            {
                this.MD5 = new MD5Wrapper();
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
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;
            }
        }