示例#1
0
        public static string GetMD5HashAsHexString(byte[] data)
        {
            var md5Implementation = System.Security.Cryptography.MD5.Create();

            byte[] hashData = md5Implementation.ComputeHash(data);
            return(GeneralConverters.ByteArrayToHexString(hashData));
        }
示例#2
0
        public static string GetSHA512HashAsHexString(byte[] data)
        {
            System.Security.Cryptography.SHA256 sha512Implementation = System.Security.Cryptography.SHA256.Create();
            var hashData = sha512Implementation.ComputeHash(data);

            return(GeneralConverters.ByteArrayToHexString(hashData));
        }
示例#3
0
        public static string GetCRC326HashAsHexString(byte[] data)
        {
            var crc32Implementation = new CRC32();

            byte[] hashData = crc32Implementation.ComputeHash(data);
            return(GeneralConverters.ByteArrayToHexString(hashData));
        }
示例#4
0
 private void UpdateHashTextField(object sender, EventArgs e)
 {
     if (hashBytes != null)
     {
         currentHashOutputTextBox.Text = GeneralConverters.ByteArrayToHexString(hashBytes);
     }
 }
示例#5
0
        private static string CreateApplicationSalt()
        {
            var randomBytes = new byte[512];

            using (RandomNumberGenerator random = RandomNumberGenerator.Create())
            {
                random.GetBytes(randomBytes);
                return(GeneralConverters.ByteArrayToHexString(randomBytes));
            }
        }
        public void TestPasswordDerivates()
        {
            RandomNumberGenerator rng = RandomNumberGenerator.Create();

            byte[] salt = new byte[32];
            rng.GetBytes(salt);

            string password = SHA256.GetSHA256HashAsHexString(GeneralConverters.StringToByteArray("MartinDahl"));

            Rfc2898DeriveBytes pDeriveBytes  = new Rfc2898DeriveBytes(password, salt, 1000);
            Rfc2898DeriveBytes pDeriveBytes2 = new Rfc2898DeriveBytes(password, salt, 1000);

            string a1 = GeneralConverters.ByteArrayToHexString(pDeriveBytes.GetBytes(16));
            string a2 = GeneralConverters.ByteArrayToHexString(pDeriveBytes2.GetBytes(16));

            Assert.IsTrue(a1 == a2, "Passwords derived was not correct");
        }
示例#7
0
        public void GenrateSFVFile(StringCollection filePathCollection, string sfvFilename)
        {
            using (var fs = File.Create(sfvFilename))
            {
                var CRC32HashImplemenation = new CRC32();

                // Write Header
                var sw = new StreamWriter(fs);
                sw.WriteLine(CHECKSUM_FILE_HEADER, _applicationName, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("HH:mm:ss"));

                _checksumProgress.FilesTotal = filePathCollection.Count;
                _checksumProgress.Text       = "Generating SFV file header";

                if (_progress != null)
                {
                    _progress.Report(_checksumProgress);
                }

                foreach (string filename in filePathCollection)
                {
                    var fileInfo = new FileInfo(filename);

                    if (!fileInfo.Exists)
                    {
                        _checksumProgress.FilesTotal = _checksumProgress.FilesTotal - 1;
                        continue;
                    }

                    sw.WriteLine(CHECKSUM_FILE_INFO, FormatFileSize(fileInfo.Length, 14), fileInfo.LastWriteTime.ToString("HH:mm:ss"), fileInfo.LastWriteTime.ToString("yyyy-MM-dd"), GeneralConverters.GetFileNameFromPath(filename));
                }

                foreach (string filename in filePathCollection)
                {
                    _checksumProgress.Text = "Processing file: " + filename;

                    if (_progress != null)
                    {
                        _progress.Report(_checksumProgress);
                    }

                    var fileInfo = new FileInfo(filename);

                    if (!fileInfo.Exists)
                    {
                        continue;
                    }
                    try
                    {
                        string hexChecksum = GeneralConverters.ByteArrayToHexString(CRC32HashImplemenation.ComputeHash(fileInfo.OpenRead()));
                        sw.WriteLine(GeneralConverters.GetFileNameFromPath(filename) + " " + hexChecksum);
                        _checksumProgress.DataRead = _checksumProgress.DataRead + fileInfo.Length;
                    }
                    catch (Exception ex)
                    {
                        _checksumProgress.Text = ex.Message;
                    }


                    _checksumProgress.FilesCompleted = _checksumProgress.FilesCompleted + 1;
                    _checksumProgress.TotalProgress  = _checksumProgress.FilesCompleted * 100 / _checksumProgress.FilesTotal;

                    if (_progress != null)
                    {
                        _progress.Report(_checksumProgress);
                    }
                }

                fs.Flush();
                fs.Close();

                if (_progress != null)
                {
                    _checksumProgress.Text          = "SFV file generation completed";
                    _checksumProgress.TotalProgress = 100;
                    _checksumProgress.Completed     = true;
                    _progress.Report(_checksumProgress);
                }
            }
        }