Exemplo n.º 1
0
        public void TestGetHashFromPaths()
        {
            string path1 = Path.Combine(Environment.CurrentDirectory, "test1.txt");

            File.WriteAllText(path1, dataToTimestamp);
            string path2 = Path.Combine(Environment.CurrentDirectory, "test2.txt");

            File.WriteAllText(path2, dataToTimestamp2);

            string[] paths = { path1, path2 };

            TimestampData timestampData = new TimestampData(paths);

            byte[] result = timestampData.GetHashedData(HashAlgorithm.SHA1);

            byte[][] datas =
            {
                Encoding.UTF8.GetBytes(dataToTimestamp),
                Encoding.UTF8.GetBytes(dataToTimestamp2)
            };

            System.Security.Cryptography.HashAlgorithm algorithm = new System.Security.Cryptography.SHA1Cng();
            for (int i = 0; i < datas.Length - 1; i++)
            {
                algorithm.TransformBlock(datas[i], 0, datas[i].Length, datas[i], 0);
            }
            algorithm.TransformFinalBlock(datas[datas.Length - 1], 0, datas[datas.Length - 1].Length);
            byte[] expectedResult = algorithm.Hash;

            Assert.IsTrue(result.SequenceEqual(expectedResult));
        }
Exemplo n.º 2
0
        public void TestGetHashFromByteArraysWrongOrder()
        {
            byte[][] datas =
            {
                Encoding.UTF8.GetBytes(dataToTimestamp),
                Encoding.UTF8.GetBytes(dataToTimestamp2)
            };
            TimestampData timestampData = new TimestampData(datas);

            byte[] result = timestampData.GetHashedData(HashAlgorithm.SHA1);

            System.Security.Cryptography.HashAlgorithm algorithm = new System.Security.Cryptography.SHA1Cng();
            for (int i = datas.Length - 1; i >= 1; i--)
            {
                algorithm.TransformBlock(datas[i], 0, datas[i].Length, datas[i], 0);
            }
            algorithm.TransformFinalBlock(datas[0], 0, datas[0].Length);
            byte[] expectedResult = algorithm.Hash;;

            Assert.IsFalse(result.SequenceEqual(expectedResult));
        }