Esempio n. 1
0
        public static string GetHashSha512(string inputString)
        {
            var sb        = new StringBuilder();
            var alghoritm = new SHA2Managed(512);

            return(ByteArrayToString(alghoritm.ComputeHash(Encoding.UTF8.GetBytes(inputString))));
        }
Esempio n. 2
0
        static void Main()
        {
            var stopwatch = new Stopwatch();


            byte[] data = { 0, 0, 5, 1, 1, 2 };
            string word = "abc";


            Sha1 hash = new Sha1();

            stopwatch.Start();
            Console.WriteLine("Proper HASH SHA1(data): " + UintArrayToString(hash.Hash(data)));
            stopwatch.Stop();
            Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s");
            stopwatch.Reset();
            stopwatch.Start();
            Console.WriteLine("Proper HASH SHA1 (word): " + UintArrayToString(hash.Hash(Encoding.ASCII.GetBytes(word))));
            stopwatch.Stop();
            Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s");
            Console.WriteLine($"Data hashed in: {stopwatch.ElapsedTicks} ticks");
            Console.WriteLine($"Speed of hashing: {Encoding.ASCII.GetBytes(word).Length * 1000000 / stopwatch.Elapsed.Ticks} bps");


            SHA3Managed hash5 = new SHA3Managed(512);

            //stopwatch.Start();
            //Console.WriteLine("Proper HASH SHA3-512(data): " + ToHexString(hash5.ComputeHash(data)));
            //stopwatch.Stop();
            //Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s");
            stopwatch.Reset();
            stopwatch.Start();
            Console.WriteLine("Proper HASH SHA3-512 (word): " + ByteArrayToString(hash5.ComputeHash(Encoding.UTF8.GetBytes(word))));
            stopwatch.Stop();
            Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s");
            Console.WriteLine($"Data hashed in: {stopwatch.ElapsedTicks} ticks");
            Console.WriteLine("Speed of hashing: {0:f2} bps", (double)(Encoding.ASCII.GetBytes(word).Length / 1024) * 1000L * 1000L * 10L / (stopwatch.ElapsedTicks));

            SHA2Managed hash6 = new SHA2Managed(512);

            stopwatch.Reset();
            Console.WriteLine("Proper HASH SHA-512(word): " + ByteArrayToString(hash6.ComputeHash(Encoding.UTF8.GetBytes(word))));

            SHA2Managed hash7 = new SHA2Managed(224);

            stopwatch.Reset();
            Console.WriteLine("Proper HASH SHA-224(word): " + ByteArrayToString(hash7.ComputeHash(Encoding.UTF8.GetBytes(word))));

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new HashFunctionAnalizerForm());
        }
Esempio n. 3
0
        internal void GeneratingTextHash(string hashName)
        {
            HashAlgorithm alghorithm;

            switch (hashName)
            {
            case "SHA1":
                alghorithm = new HashFunctions.SHA1();
                HashingText(hashName, alghorithm);
                break;

            case "SHA224":
                alghorithm = new SHA2Managed(224);
                HashingText(hashName, alghorithm);
                break;

            case "SHA256":
                alghorithm = new SHA2Managed(256);
                HashingText(hashName, alghorithm);
                break;

            case "SHA384":
                alghorithm = new SHA2Managed(384);
                HashingText(hashName, alghorithm);
                break;

            case "SHA512":
                alghorithm = new SHA2Managed(512);
                HashingText(hashName, alghorithm);
                break;

            case "SHA3-224":
                alghorithm = new SHA3(224);
                HashingText(hashName, alghorithm);
                break;

            case "SHA3-256":
                alghorithm = new SHA3(256);
                HashingText(hashName, alghorithm);
                break;

            case "SHA3-384":
                alghorithm = new SHA3(384);
                HashingText(hashName, alghorithm);
                break;

            case "SHA3-512":
                alghorithm = new SHA3(512);
                HashingText(hashName, alghorithm);
                break;
            }
        }
Esempio n. 4
0
        internal void AvalancheTestOfHashFunctions(string hashName)
        {
            HashAlgorithm alghorithm;

            switch (hashName)
            {
            case "SHA1":
                alghorithm = new HashFunctions.SHA1();
                CreateAvalancheBitmapAtRuntime(hashName, alghorithm);
                break;

            case "SHA224":
                alghorithm = new SHA2Managed(224);
                CreateAvalancheBitmapAtRuntime(hashName, alghorithm);
                break;

            case "SHA256":
                alghorithm = new SHA2Managed(256);
                CreateAvalancheBitmapAtRuntime(hashName, alghorithm);
                break;

            case "SHA384":
                alghorithm = new SHA2Managed(384);
                CreateAvalancheBitmapAtRuntime(hashName, alghorithm);
                break;

            case "SHA512":
                alghorithm = new SHA2Managed(512);
                CreateAvalancheBitmapAtRuntime(hashName, alghorithm);
                break;

            case "SHA3-224":
                alghorithm = new SHA3(224);
                CreateAvalancheBitmapAtRuntime(hashName, alghorithm);
                break;

            case "SHA3-256":
                alghorithm = new SHA3(256);
                CreateAvalancheBitmapAtRuntime(hashName, alghorithm);
                break;

            case "SHA3-384":
                alghorithm = new SHA3(384);
                CreateAvalancheBitmapAtRuntime(hashName, alghorithm);
                break;

            case "SHA3-512":
                alghorithm = new SHA3(512);
                CreateAvalancheBitmapAtRuntime(hashName, alghorithm);
                break;
            }
        }
Esempio n. 5
0
        public void HashAlghorithmSelectedFile(string hashName)
        {
            HashAlgorithm alghorithm;

            switch (hashName)
            {
            case "SHA1":
                alghorithm = new HashFunctions.SHA1();
                HashSelectedFile(hashName, alghorithm);
                break;

            case "SHA224":
                alghorithm = new SHA2Managed(224);
                HashSelectedFile(hashName, alghorithm);
                break;

            case "SHA256":
                alghorithm = new SHA2Managed(256);
                HashSelectedFile(hashName, alghorithm);
                break;

            case "SHA384":
                alghorithm = new SHA2Managed(384);
                HashSelectedFile(hashName, alghorithm);
                break;

            case "SHA512":
                alghorithm = new SHA2Managed(512);
                HashSelectedFile(hashName, alghorithm);
                break;

            case "SHA3-224":
                alghorithm = new SHA3(224);
                HashSelectedFile(hashName, alghorithm);
                break;

            case "SHA3-256":
                alghorithm = new SHA3(256);
                HashSelectedFile(hashName, alghorithm);
                break;

            case "SHA3-384":
                alghorithm = new SHA3(384);
                HashSelectedFile(hashName, alghorithm);
                break;

            case "SHA3-512":
                alghorithm = new SHA3(512);
                HashSelectedFile(hashName, alghorithm);
                break;
            }
        }
Esempio n. 6
0
        private double speedTestOfHashFunctions(string hashName)
        {
            var someData = new byte[1000000];


            //randomize data
            for (int i = 0; i < someData.Length; i++)
            {
                someData[i] = Convert.ToByte(randomizeValue());
            }

            var    times     = 100;
            var    stopWatch = new Stopwatch();
            double result;
            int    collumnCounter;


            for (int i = 0; i < times; i++)
            {
                if (i % 5 == 0)
                {
                    dataGridView1.Columns.Add($"{i} Mb", $"{i} Mb");
                }
            }


            switch (hashName)
            {
            case "SHA1":
                var alghorithmSha1 = new Sha1();
                dataGridView1.Rows.Add();
                collumnCounter = 2;
                stopWatch.Reset();
                stopWatch.Start();
                for (int i = 0; i < times; i++)
                {
                    alghorithmSha1.Hash(someData);

                    if (i % 5 == 0)
                    {
                        double secondsy = (double)stopWatch.ElapsedMilliseconds / 1000;
                        result = (double)(i / secondsy);
                        dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex + (dataGridView1.RowCount - 1)].Cells[collumnCounter++].Value = $"{result:f2}";
                    }
                }
                stopWatch.Stop();
                break;

            case "SHA224":
                var alghorithmSha224 = new SHA2Managed(224);
                stopWatch.Reset();
                stopWatch.Start();
                for (int i = 0; i < times; i++)
                {
                    alghorithmSha224.ComputeHash(someData);
                }
                stopWatch.Stop();
                break;

            case "SHA256":
                var alghorithmSha256 = new SHA2Managed(256);
                stopWatch.Reset();
                stopWatch.Start();
                for (int i = 0; i < times; i++)
                {
                    alghorithmSha256.ComputeHash(someData);
                }
                stopWatch.Stop();
                break;

            case "SHA384":
                var alghorithmSha384 = new SHA2Managed(384);
                stopWatch.Reset();
                stopWatch.Start();
                for (int i = 0; i < times; i++)
                {
                    alghorithmSha384.ComputeHash(someData);
                }
                stopWatch.Stop();
                break;

            case "SHA512":
                var alghorithmSha512 = new SHA2Managed(512);
                dataGridView1.Rows.Add();
                collumnCounter = 2;
                stopWatch.Reset();
                stopWatch.Start();
                for (int i = 0; i < times; i++)
                {
                    alghorithmSha512.ComputeHash(someData);

                    if (i % 5 == 0)
                    {
                        double secondsy = (double)stopWatch.ElapsedMilliseconds / 1000;
                        result = (double)(i / secondsy);
                        dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex + (dataGridView1.RowCount - 1)].Cells[collumnCounter++].Value = $"{result:f2}";
                    }
                }
                stopWatch.Stop();
                break;

            case "SHA3-512":
                var alghorithmSha3_512 = new SHA3Managed();
                dataGridView1.Rows.Add();
                collumnCounter = 2;
                stopWatch.Reset();
                stopWatch.Start();
                for (int i = 0; i < times; i++)
                {
                    alghorithmSha3_512.ComputeHash(someData);

                    if (i % 5 == 0)
                    {
                        double secondsy = (double)stopWatch.ElapsedMilliseconds / 1000;
                        result = (double)(i / secondsy);
                        dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex + (dataGridView1.RowCount - 1)].Cells[collumnCounter++].Value = $"{result:f2}";
                    }
                }
                stopWatch.Stop();
                break;

            default:

                break;
            }


            double seconds = (double)stopWatch.ElapsedMilliseconds / 1000;

            Console.WriteLine("HASH {0} with speed: {1} Mb data in {2:f2}", hashName, times, seconds);

            result = (double)(times / seconds);

            return(result);
        }
Esempio n. 7
0
        private void generateFileHashBtn_Click(object sender, EventArgs e)
        {
            var stopwatch       = new Stopwatch();
            var stopwatchSHA224 = new Stopwatch();
            var stopwatchSHA256 = new Stopwatch();
            var stopwatchSHA384 = new Stopwatch();
            var stopwatchSHA512 = new Stopwatch();


            Stream fileStream     = null;
            var    openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = "\\";
            openFileDialog.Filter           = @"All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (!((fileStream = openFileDialog.OpenFile()) == null))
                    {
                        using (fileStream)
                        {
                            var imageData = new byte[fileStream.Length];

                            fileStream.Read(imageData, 0, Convert.ToInt32(fileStream.Length));
                            var fs = fileStream as FileStream;


                            var hashSha1   = new Sha1();
                            var hashSha224 = new SHA2Managed(224);
                            var hashSha256 = new SHA2Managed(256);
                            var hashSha384 = new SHA2Managed(384);
                            var hashSha512 = new SHA2Managed(512);
                            var hashSha3   = new SHA3Managed();

                            stopwatch.Start();
                            Console.WriteLine("FILE HASH SHA1: " +
                                              UintArrayToString(hashSha1.Hash(FileToByteArray(fs.Name))));
                            stopwatch.Stop();
                            Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s");

                            stopwatchSHA224.Start();
                            Console.WriteLine("FILE HASH SHA224: " +
                                              ByteArrayToString(hashSha224.ComputeHash(FileToByteArray(fs.Name))));
                            stopwatchSHA224.Stop();
                            Console.WriteLine($"Data hashed in: {stopwatchSHA224.Elapsed} s");

                            stopwatchSHA256.Start();
                            Console.WriteLine("FILE HASH SHA256: " +
                                              ByteArrayToString(hashSha256.ComputeHash(FileToByteArray(fs.Name))));
                            stopwatchSHA256.Stop();
                            Console.WriteLine($"Data hashed in: {stopwatchSHA256.Elapsed} s");

                            stopwatchSHA384.Start();
                            Console.WriteLine("FILE HASH SHA384: " +
                                              ByteArrayToString(hashSha384.ComputeHash(FileToByteArray(fs.Name))));
                            stopwatchSHA384.Stop();
                            Console.WriteLine($"Data hashed in: {stopwatchSHA384.Elapsed} s");


                            stopwatchSHA512.Start();
                            Console.WriteLine("FILE HASH SHA512: " +
                                              ByteArrayToString(hashSha512.ComputeHash(FileToByteArray(fs.Name))));
                            stopwatchSHA512.Stop();
                            Console.WriteLine($"Data hashed in: {stopwatchSHA512.Elapsed} s");


                            stopwatchSHA512.Reset();
                            stopwatchSHA512.Start();
                            Console.WriteLine("FILE HASH SHA3-512: " +
                                              ByteArrayToString(hashSha3.ComputeHash(FileToByteArray(fs.Name))));
                            stopwatchSHA512.Stop();
                            Console.WriteLine($"Data hashed in: {stopwatchSHA512.Elapsed} s");

                            //Write length of file
                            Console.WriteLine($"File Length: {fileStream.Length}");

                            //Close the File Stream
                            fileStream.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Esempio n. 8
0
        internal void SpeedTestOfHashFunctions(string hashName)
        {
            HashAlgorithm alghorithm;

            //generating randomize data
            var someData = new byte[1048576];

            for (var i = 0; i < someData.Length; i++)
            {
                someData[i] = Convert.ToByte(RandomizeValue());
            }

            var dataSize = Convert.ToInt32(dataSizeBar.Invoke(new Func <int>(DataSizeBarValue)));

            //generating missing collumns
            if (dataGridViewSpeedTest.ColumnCount <= 2 || dataGridViewSpeedTest.ColumnCount < (dataSize / 5))
            {
                dataGridViewSpeedTest.Invoke(new Action <int>(AddCollumn), new object[] { dataSize });
            }

            switch (hashName)
            {
            case "SHA1":
                alghorithm = new HashFunctions.SHA1();
                SpeedCounting(alghorithm, hashName, someData, dataSize);
                break;

            case "SHA224":
                alghorithm = new SHA2Managed(224);
                SpeedCounting(alghorithm, hashName, someData, dataSize);
                break;

            case "SHA256":
                alghorithm = new SHA2Managed(256);
                SpeedCounting(alghorithm, hashName, someData, dataSize);
                break;

            case "SHA384":
                alghorithm = new SHA2Managed(384);
                SpeedCounting(alghorithm, hashName, someData, dataSize);
                break;

            case "SHA512":
                alghorithm = new SHA2Managed(512);
                SpeedCounting(alghorithm, hashName, someData, dataSize);
                break;

            case "SHA3-224":
                alghorithm = new SHA3(224);
                SpeedCounting(alghorithm, hashName, someData, dataSize);
                break;

            case "SHA3-256":
                alghorithm = new SHA3(256);
                SpeedCounting(alghorithm, hashName, someData, dataSize);
                break;

            case "SHA3-384":
                alghorithm = new SHA3(384);
                SpeedCounting(alghorithm, hashName, someData, dataSize);
                break;

            case "SHA3-512":
                alghorithm = new SHA3(512);
                SpeedCounting(alghorithm, hashName, someData, dataSize);
                break;
            }
        }