System.Security.Cryptography.HashAlgorithm.ComputeHash(System.IO.Stream)

Here are the examples of the csharp api System.Security.Cryptography.HashAlgorithm.ComputeHash(System.IO.Stream) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

556 Examples 7

19 View Source File : Utils.cs
License : MIT License
Project Creator : Assistant

public static string CalculateMD5(string filename)
        {
            using (var md5 = MD5.Create())
            {
                using (var stream = File.OpenRead(filename))
                {
                    var hash = md5.ComputeHash(stream);
                    return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
                }
            }
        }

19 View Source File : Tools.cs
License : MIT License
Project Creator : AyrA

public static string GetHash(Stream S)
        {
            using (var H = SHA1.Create())
            {
                byte[] Data = H.ComputeHash(S);
                return string.Join("", Data.Select(m => m.ToString("X2")).ToArray());
            }
        }

19 View Source File : ExpRoomEditor.cs
License : Apache License 2.0
Project Creator : allenai

public static string CreateSHA256Hash(string path) {
        SHA256 hasher = SHA256.Create();

        using (System.IO.FileStream fs = System.IO.File.OpenRead(path)) {
            return string.Join("", hasher.ComputeHash(fs).Select(b => b.ToString("x2")).ToArray());
        }
    }

19 View Source File : Program.cs
License : GNU General Public License v3.0
Project Creator : anydream

public static byte[] GetFileHash(string file)
		{
			try
			{
				using (var md5 = MD5.Create())
				{
					using (var stream = File.OpenRead(file))
					{
						return md5.ComputeHash(stream);
					}
				}
			}
			catch (IOException)
			{
				return null;
			}
		}

19 View Source File : Utils.cs
License : MIT License
Project Creator : AmazingDM

public static string SHA256CheckSum(string filePath)
        {
            try
            {
                var sha256 = SHA256.Create();
                var fileStream = File.OpenRead(filePath);
                return sha256.ComputeHash(fileStream).Aggregate(string.Empty, (current, b) => current + b.ToString("x2"));
            }
            catch
            {
                return "";
            }
        }

19 View Source File : AssetDuplicateTreeModel.cs
License : MIT License
Project Creator : akof1314

private List<FileMd5Info> GetFileMd5Infos(List<string> fileArray)
        {
            var style = replacedetDanshariStyle.Get();
            var fileList = new List<FileMd5Info>();

            for (int i = 0; i < fileArray.Count;)
            {
                string file = fileArray[i];
                if (string.IsNullOrEmpty(file))
                {
                    i++;
                    continue;
                }
                EditorUtility.DisplayProgressBar(style.progressreplacedle, file, i * 1f / fileArray.Count);
                try
                {
                    using (var md5 = MD5.Create())
                    {
                        FileInfo fileInfo = new FileInfo(file);
                        using (var stream = File.OpenRead(fileInfo.FullName))
                        {
                            FileMd5Info info = new FileMd5Info();
                            info.filePath = fileInfo.FullName;
                            info.fileSize = fileInfo.Length;
                            info.fileTime = fileInfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss");
                            info.md5 = BitConverter.ToString(md5.ComputeHash(stream)).ToLower();
                            fileList.Add(info);
                        }
                    }

                    i++;
                }
                catch (Exception e)
                {
                    if (!EditorUtility.DisplayDialog(style.errorreplacedle, file + "\n" + e.Message,
                        style.continueStr, style.cancelStr))
                    {
                        EditorUtility.ClearProgressBar();
                        return null;
                    }
                }
            }
            return fileList;
        }

19 View Source File : OnlineUpdate.cs
License : GNU General Public License v3.0
Project Creator : audiamus

private string computeMd5HashForFile (string filePath) {
      using (var md5 = MD5.Create ()) {
        using (var stream = File.OpenRead (filePath)) {
          var hash = md5.ComputeHash (stream);
          return BitConverter.ToString (hash).Replace ("-", "").ToLowerInvariant ();
        }
      }
    }

19 View Source File : Utility.cs
License : MIT License
Project Creator : Adoxio

public static string ComputeETag(Stream stream)
		{
			using (var sha256 = new SHA256CryptoServiceProvider())
			{
				var hash = Convert.ToBase64String(sha256.ComputeHash(stream));
				return hash;
			}
		}

19 View Source File : Security.cs
License : MIT License
Project Creator : b9q

private static string get_sha256()
        {
            using (FileStream stream = File.OpenRead(Application.ExecutablePath))
            {
                SHA256Managed sha = new SHA256Managed();
                byte[] hash = sha.ComputeHash(stream);
                return BitConverter.ToString(hash).Replace("-", String.Empty);
            }
        }

19 View Source File : Program.cs
License : GNU General Public License v3.0
Project Creator : AdriaandeJongh

static string GetMD5(string filepath)
        {
            using (var md5 = MD5.Create())
            {
                using (var stream = File.OpenRead(filepath))
                {
                    return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", string.Empty).ToLowerInvariant();
                }
            }
        }

19 View Source File : ETagMiddleware.cs
License : MIT License
Project Creator : anteatergames

private static string CalculateChecksum(MemoryStream ms)
        {
            string checksum = "";

            using (SHA1 algo = SHA1.Create())
            {
                ms.Position = 0;
                byte[] bytes = algo.ComputeHash(ms);
                checksum = $"\"{WebEncoders.Base64UrlEncode(bytes)}\"";
            }

            return checksum;
        }

19 View Source File : MD5Helper.cs
License : MIT License
Project Creator : AnotherEnd15

public static string FileMD5(string filePath)
		{
			byte[] retVal;
            using (FileStream file = new FileStream(filePath, FileMode.Open))
			{
				MD5 md5 = new MD5CryptoServiceProvider();
				retVal = md5.ComputeHash(file);
			}
			return retVal.ToHex("x2");
		}

19 View Source File : mainForm.cs
License : MIT License
Project Creator : ajohns6

private Boolean checkHash(string file)
        {
            using (SHA1Managed sha1Hasher = new SHA1Managed())
            using (FileStream stream = new FileStream(file, FileMode.Open))
            using (BufferedStream buffer = new BufferedStream(stream))
            {
                byte[] hash = sha1Hasher.ComputeHash(buffer);
                StringBuilder hashString = new StringBuilder(2 * hash.Length);
                foreach (byte b in hash)
                {
                    hashString.AppendFormat("{0:x2}", b);
                }

                if (hashString.ToString() == "9bef1128717f958171a4afac3ed78ee2bb4e86ce") return true;
            }
            return false;
        }

19 View Source File : FileUtils.cs
License : MIT License
Project Creator : aprilyush

public static string ComputeHash(string filePath)
        {
            using (var md5 = MD5.Create())
            {
                using (var stream = File.OpenRead(filePath))
                {
                    return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "‌​").ToLower();
                }
            }
        }

19 View Source File : StreamVideoSourceHandler.cs
License : MIT License
Project Creator : adamfisher

private string GetFileName(Stream stream, string format)
        {
            var hasher = MD5.Create();
            var hashBytes = hasher.ComputeHash(stream);
			stream.Position = 0;
			var hash = Convert.ToBase64String(hashBytes)
				.Replace("=", string.Empty)
				.Replace("\\", string.Empty)
				.Replace("/", string.Empty);
			return $"{hash}_temp.{format}";
        }

19 View Source File : FileUtils.cs
License : MIT License
Project Creator : Astropilot

public static string ComputeHash(this FileInfo file)
        {
            using (var md5 = System.Security.Cryptography.MD5.Create())
            {
                using (var stream = File.OpenRead(file.FullName))
                {
                    var hash = md5.ComputeHash(stream);
                    return BitConverter.ToString(hash).Replace("-", "");
                }
            }
        }

19 View Source File : Manager.cs
License : Apache License 2.0
Project Creator : Algoryx

public static bool HasBeenChanged( FileInfo v1, FileInfo v2 )
    {
      if ( v1 == null || !v1.Exists || v2 == null || !v2.Exists )
        return false;

      Func<FileInfo, byte[]> generateMd5 = fi =>
      {
        using ( var stream = fi.OpenRead() ) {
          return System.Security.Cryptography.MD5.Create().ComputeHash( stream );
        }
      };

      return !generateMd5( v1 ).SequenceEqual( generateMd5( v2 ) );
    }

19 View Source File : GameVerifier.cs
License : MIT License
Project Creator : automuteus

public static bool VerifyGameHash(string executablePath)
        {
            // This is for Beta detection.
            var baseDllFolder = Directory.GetParent(executablePath).FullName;

            var amongus_exePath = Path.Join(baseDllFolder, "Among Us.exe");
            var gamereplacedembly_dllPath = Path.Join(baseDllFolder, "Gamereplacedembly.dll");
            var amongus_exeHash = String.Empty;
            var gamereplacedembly_dllHash = String.Empty;
            
            using (SHA1Managed sha1 = new SHA1Managed())
            {
                using (FileStream fs = new FileStream(amongus_exePath, FileMode.Open))
                {
                    using (var bs = new BufferedStream(fs))
                    {
                        var hash = sha1.ComputeHash(bs);
                        StringBuilder steam_apihashSb = new StringBuilder(2 * hash.Length);
                        foreach (byte byt in hash)
                        {
                            steam_apihashSb.AppendFormat("{0:X2}", byt);
                        }

                        amongus_exeHash = steam_apihashSb.ToString();
                    }
                }    
                    
                using (FileStream fs = new FileStream(gamereplacedembly_dllPath, FileMode.Open))
                {
                    using (var bs = new BufferedStream(fs))
                    {
                        var hash = sha1.ComputeHash(bs);
                        StringBuilder steam_api64hashSb = new StringBuilder(2 * hash.Length);
                        foreach (byte byt in hash)
                        {
                            steam_api64hashSb.AppendFormat("{0:X2}", byt);
                        }

                        gamereplacedembly_dllHash = steam_api64hashSb.ToString();
                    }
                }
            }
            return (String.Equals(amongusexe_orig_hash.ToUpper(), amongus_exeHash) &&
                    String.Equals(gamereplacedembly_orig_hash.ToUpper(), gamereplacedembly_dllHash));
        }

19 View Source File : RSAEncode.cs
License : Apache License 2.0
Project Creator : 91270

public bool GetHash(FileStream objFile, ref byte[] HashData)
        {

            //从文件中取得Hash描述   
            HashAlgorithm MD5 = HashAlgorithm.Create("MD5");
            HashData = MD5.ComputeHash(objFile);
            objFile.Close();

            return true;

        }

19 View Source File : IOUtils.cs
License : MIT License
Project Creator : azist

public static byte[] ToMD5(this Stream input)
    {
      if (input == null) return new byte[16];

      using (var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider())
      {
        return md5.ComputeHash(input);
      }
    }

19 View Source File : HelperMethods.cs
License : GNU General Public License v3.0
Project Creator : AM2R-Community-Developers

public static string CalculateMD5(string filename)
        {
            // Check if File exists first
            if (!File.Exists(filename))
                return "";

            using (var stream = File.OpenRead(filename))
            {
                using (var md5 = MD5.Create())
                {
                    var hash = md5.ComputeHash(stream);
                    return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
                }
            }
        }

19 View Source File : ModPacker.cs
License : GNU General Public License v3.0
Project Creator : AM2R-Community-Developers

private string CalculateMD5(string filename)
        {
            using (var stream = File.OpenRead(filename))
            {
                using (var md5 = MD5.Create())
                {
                    var hash = md5.ComputeHash(stream);
                    return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
                }
            }
        }

19 View Source File : RSAEncode.cs
License : Apache License 2.0
Project Creator : 91270

public bool GetHash(FileStream objFile, ref string strHashData)
        {

            //从文件中取得Hash描述   
            byte[] HashData;
            HashAlgorithm MD5 = HashAlgorithm.Create("MD5");
            HashData = MD5.ComputeHash(objFile);
            objFile.Close();

            strHashData = Convert.ToBase64String(HashData);

            return true;

        }

19 View Source File : SongDownloader.cs
License : MIT License
Project Creator : andruzzzhka

public static bool CreateMD5FromFile(string path, out string hash)
        {
            hash = "";
            if (!File.Exists(path)) return false;
            using (MD5 md5 = MD5.Create())
            {
                using (var stream = File.OpenRead(path))
                {
                    byte[] hashBytes = md5.ComputeHash(stream);

                    StringBuilder sb = new StringBuilder();
                    foreach (byte hashByte in hashBytes)
                    {
                        sb.Append(hashByte.ToString("X2"));
                    }

                    hash = sb.ToString();
                    return true;
                }
            }
        }

19 View Source File : Helpers.cs
License : GNU General Public License v3.0
Project Creator : Aetsu

public static void CalculateMD5Files(string folder)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("     Calculating md5...");
            Console.ResetColor();
            string[] fileList = Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories);
            List<string> md5List = new List<string>();
            foreach (string filename in fileList)
            {
                using (var md5 = MD5.Create())
                {
                    using (var stream = File.OpenRead(filename))
                    {
                        var hash = md5.ComputeHash(stream);
                        md5List.Add(filename + " - " + BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant());
                    }
                }
            }
            File.WriteAllLines(Path.Combine(new string[] { folder, "md5.txt" }), md5List);
        }

19 View Source File : CryptoService.cs
License : MIT License
Project Creator : ansel86castro

public virtual byte[] ComputeHash(Stream data)
        {
            byte[] result = null;
            using (SHA1 sha = new SHA1Managed()) //new SHA1CryptoServiceProvider();
            {
                result = sha.ComputeHash(data);
            }
            return result;
        }

19 View Source File : Crypter.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : anoyetta

public static bool IsMatchHash(
            string file1,
            string file2)
        {
            if (!File.Exists(file1) ||
                !File.Exists(file2))
            {
                return false;
            }

            var r = false;

            using (var md5 = MD5.Create())
            {
                using (var fs1 = new FileStream(file1, FileMode.Open, FileAccess.Read))
                using (var fs2 = new FileStream(file2, FileMode.Open, FileAccess.Read))
                {
                    var hash1 = md5.ComputeHash(fs1);
                    var hash2 = md5.ComputeHash(fs2);

                    r = string.Equals(
                        BitConverter.ToString(hash1),
                        BitConverter.ToString(hash2),
                        StringComparison.OrdinalIgnoreCase);
                }
            }

            return r;
        }

19 View Source File : RSACryption.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public bool GetHash(FileStream objFile, ref string strHashData)
        {
            //从文件中取得Hash描述 
            byte[] HashData;
            HashAlgorithm MD5 = HashAlgorithm.Create("MD5");
            HashData = MD5.ComputeHash(objFile);
            objFile.Close();

            strHashData = Convert.ToBase64String(HashData);

            return true;
        }

19 View Source File : general.cs
License : GNU General Public License v3.0
Project Creator : antikmozib

public static string hashFile(string path)
        {
            try
            {
                using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider())
                    {
                        byte[] hash;
                        hash = md5.ComputeHash(stream);
                        return System.Text.Encoding.Unicode.GetString(hash);
                    }
                }
            }
            catch (Exception)
            {
                return "";
            }
        }

19 View Source File : BTCChinaAPI.cs
License : MIT License
Project Creator : aabiryukov

private string GetHMACSHA1Hash(NameValueCollection parameters)
        {
            var keyValues = new List<string>();
            foreach (string key in parameters)
            {
                keyValues.Add(key + "=" + parameters[key]);
            }
            string input = String.Join("&", keyValues.ToArray());
            //signature string for hash is NOT JSON-compatible
            //watch out for API changes on the website.
            input = input.Replace("\"", "");
            input = input.Replace("true", "1");
            input = input.Replace("false", "");
            input = input.Replace("null", "");

            //Console.WriteLine(input);

	        using (var hmacsha1 = new HMACSHA1(Encoding.ASCII.GetBytes(secretKey)))
	        {
		        byte[] hashData;
		        using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(input)))
		        {
			        hashData = hmacsha1.ComputeHash(stream);
		        }

		        // Format as hexadecimal string.
		        var hashBuilder = new StringBuilder();
		        foreach (byte data in hashData)
		        {
			        hashBuilder.Append(data.ToString("x2", CultureInfo.InvariantCulture));
		        }
		        return hashBuilder.ToString();
	        }
        }

19 View Source File : Issues.cs
License : Apache License 2.0
Project Creator : Appdynamics

[TestMethod, Ignore]
        public void Issue15252()
        {
            using (var p = new ExcelPackage())
            {
                var path1 = @"c:\temp\saveerror1.xlsx";
                var path2 = @"c:\temp\saveerror2.xlsx";
                var workSheet = p.Workbook.Worksheets.Add("saveerror");
                workSheet.Cells["A1"].Value = "test";

                // double save OK?
                p.SaveAs(new FileInfo(path1));
                p.SaveAs(new FileInfo(path2));

                // files are identical?
#if (Core)
                var md5 = System.Security.Cryptography.MD5.Create();
#else
                var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
#endif
                using (var fs1 = new FileStream(path1, FileMode.Open))
                using (var fs2 = new FileStream(path2, FileMode.Open))
                {
                    var hash1 = String.Join("", md5.ComputeHash(fs1).Select((x) => { return x.ToString(); }));
                    var hash2 = String.Join("", md5.ComputeHash(fs2).Select((x) => { return x.ToString(); }));
                    replacedert.AreEqual(hash1, hash2);
                }
            }
        }

19 View Source File : mainForm.cs
License : MIT License
Project Creator : ajohns6

private Boolean checkHash(string file, PAK pak)
        {
            if (pak.modURL is "") return true;
            if (pak.modHash is null)
            {
                pullJSON();
                return false;
            }

            using (SHA1Managed sha1Hasher = new SHA1Managed())
            using (FileStream stream = new FileStream(file, FileMode.Open))
            using (BufferedStream buffer = new BufferedStream(stream))
            {
                byte[] hash = sha1Hasher.ComputeHash(buffer);
                StringBuilder hashString = new StringBuilder(2 * hash.Length);
                foreach (byte b in hash)
                {
                    hashString.AppendFormat("{0:x2}", b);
                }

                if (hashString.ToString().ToUpper() == pak.modHash) return true;
            }
            return false;
        }

19 View Source File : StreamVideoSourceHandler.cs
License : MIT License
Project Creator : arqueror

private string GetFileName(Stream stream, string format)
        {
            var hasher = MD5.Create();
            var hashBytes = hasher.ComputeHash(stream);
            stream.Position = 0;
            var hash = Convert.ToBase64String(hashBytes)
                .Replace("=", string.Empty)
                .Replace("\\", string.Empty)
                .Replace("/", string.Empty);
            return $"{hash}_temp.{format}";
        }

19 View Source File : Util.cs
License : MIT License
Project Creator : 499116344

public static string GetMD5HashFromFile(string fileName)
        {
            try
            {
                var file = new FileStream(fileName, FileMode.Open);
                MD5 md5 = new MD5CryptoServiceProvider();
                var retVal = md5.ComputeHash(file);
                file.Close();

                var sb = new StringBuilder();
                foreach (var t in retVal)
                {
                    sb.Append(t.ToString("x2"));
                }

                return sb.ToString();
            }
            catch (Exception ex)
            {
                throw new Exception("GetMD5HashFromFile() fail, error:" + ex.Message);
            }
        }

19 View Source File : Utils.cs
License : MIT License
Project Creator : Assistant

public static string CalculateMD5FromStream(Stream stream)
        {
            using (var md5 = MD5.Create())
            {
                var hash = md5.ComputeHash(stream);
                return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
            }
        }

19 View Source File : Common.cs
License : MIT License
Project Creator : AlbertMN

public static string CalculateChecksum(string filename)
    {
        using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
        using (var bs = new BufferedStream(fs))
        using (var sha1 = new SHA1CryptoServiceProvider())
        {
            var hash = sha1.ComputeHash(bs);
            var formatted = new StringBuilder(2 * hash.Length);
            foreach (var b in hash)
            {
                formatted.AppendFormat("{0:X2}", b);
            }
            return formatted.ToString();
        }
    }

19 View Source File : Helpers.cs
License : GNU General Public License v3.0
Project Creator : AtomCrafty

public static string FileHash(string path) {
			using(HashAlgorithm hasher = new MD5CryptoServiceProvider())
			using(FileStream fs = new FileStream(path, FileMode.Open)) {
				return Convert.ToBase64String(hasher.ComputeHash(fs));
			}
		}

19 View Source File : SearchAutomation.cs
License : MIT License
Project Creator : ADeltaX

public static byte[] GetSHA1HashFile(string fileLocation)
        {
            try
            {
                using (FileStream fs = new FileStream(fileLocation, FileMode.Open, FileAccess.Read))
                using (var cryptoProvider = new SHA1CryptoServiceProvider())
                    return cryptoProvider.ComputeHash(fs);
            }
            catch (Exception)
            {
                return null;
            }
        }

19 View Source File : GameVerifier.cs
License : MIT License
Project Creator : automuteus

public static bool VerifySteamHash(string executablePath)
        {
           if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
           {
                //Get Steam_api.dll from (parent)filepath\Among Us_Data\Plugins\x86\steam_api.dll and steam_api64.dll
                var baseDllFolder = Path.Join(Directory.GetParent(executablePath).FullName,"/Among Us_Data/Plugins/x86/");
                if (!Directory.Exists(baseDllFolder))
                {
                    baseDllFolder = Path.Join(Directory.GetParent(executablePath).FullName, "/Among Us_Data/Plugins/x86_64/");
                }
                var steam_apiCertPath = Path.Join(baseDllFolder, "steam_api.dll");
                var steam_api64CertPath = Path.Join(baseDllFolder, "steam_api64.dll");
                var steam_apiCert = !File.Exists(steam_apiCertPath) || AuthenticodeTools.IsTrusted(steam_apiCertPath);
                var steam_api64Cert = !File.Exists(steam_api64CertPath) || AuthenticodeTools.IsTrusted(steam_api64CertPath);
                //Settings.conInterface.WriteModuleTextColored("GameVerifier",Color.Yellow,$"steam_apiCert: {steam_apiCert}");
                //Settings.conInterface.WriteModuleTextColored("GameVerifier",Color.Yellow,$"steam_api64Cert: {steam_api64Cert}");
                return (steam_apiCert) && (steam_api64Cert);
           }
            
           if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
           {
                var baseDllFolder = Path.Join(Directory.GetParent(executablePath).FullName,
                    "/Among Us_Data/Plugins/x86/");
                
                var steam_apiPath = Path.Join(baseDllFolder, "steam_api.dll");
                var steam_api64Path = Path.Join(baseDllFolder, "steam_api64.dll");
                var steam_apiHash = String.Empty;
                var steam_api64Hash = String.Empty;
                
                using (SHA1Managed sha1 = new SHA1Managed())
                {
                    
                    using (FileStream fs = new FileStream(steam_apiPath, FileMode.Open))
                    {
                        using (var bs = new BufferedStream(fs))
                        {
                            var hash = sha1.ComputeHash(bs);
                            StringBuilder steam_apihashSb = new StringBuilder(2 * hash.Length);
                            foreach (byte byt in hash)
                            {
                                steam_apihashSb.AppendFormat("{0:X2}", byt);
                            }

                            steam_apiHash = steam_apihashSb.ToString();
                        }
                    }    
                    
                    using (FileStream fs = new FileStream(steam_api64Path, FileMode.Open))
                    {
                        using (var bs = new BufferedStream(fs))
                        {
                            var hash = sha1.ComputeHash(bs);
                            StringBuilder steam_api64hashSb = new StringBuilder(2 * hash.Length);
                            foreach (byte byt in hash)
                            {
                                steam_api64hashSb.AppendFormat("{0:X2}", byt);
                            }

                            steam_api64Hash = steam_api64hashSb.ToString();
                        }
                    }
                }

                return (String.Equals(steamapi32_orig_hash.ToUpper(), steam_apiHash) &&
                        String.Equals(steamapi64_orig_hash.ToUpper(), steam_api64Hash));

           }
            
           throw new PlatformNotSupportedException();
        }

19 View Source File : CryptoUtil.cs
License : MIT License
Project Creator : aliyunmq

public byte[] ComputeMD5Hash(Stream steam)
            {
                byte[] hashed = MD5.Create().ComputeHash(steam);
                return hashed;
            }

19 View Source File : Utilities.cs
License : MIT License
Project Creator : ay2015

[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public static string HashStreamMD5(Stream stm)
        {
            stm.Position = 0;
            var hashBuilder = new StringBuilder();
            using (MD5 md5 = MD5.Create())
            {
                foreach (byte b in md5.ComputeHash(stm))
                {
                    hashBuilder.Append(b.ToString("x2", CultureInfo.InvariantCulture));
                }
            }

            return hashBuilder.ToString();
        }

19 View Source File : Ribbon.cs
License : GNU General Public License v3.0
Project Creator : 0dteam

static string CalculateMD5(string filename)
        {
            using (var md5 = MD5.Create())
            {
                using (var stream = File.OpenRead(filename))
                {
                    var hash = md5.ComputeHash(stream);
                    return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
                }
            }
        }

19 View Source File : IOUtils.cs
License : MIT License
Project Creator : azist

public static string ToMD5String(this Stream input)
    {
      if (input == null)
        return "00000000000000000000000000000000";

      using (var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider())
      {
        var hash = md5.ComputeHash(input);

        var result = new StringBuilder();

        for (var i = 0; i < hash.Length; i++)
          result.Append(hash[i].ToString("x2"));

        return result.ToString();
      }
    }

19 View Source File : CryptoService.cs
License : MIT License
Project Creator : AllocZero

public static byte[] ComputeSha256Hash(Stream stream) => Sha256HashAlgorithmInstance.ComputeHash(stream);

19 View Source File : Utility.cs
License : MIT License
Project Creator : Adoxio

public static string ComputeETag(Stream stream)
		{
			using (var sha1 = new SHA1CryptoServiceProvider())
			{
				var hash = Convert.ToBase64String(sha1.ComputeHash(stream));
				return hash;
			}
		}

19 View Source File : SteamBotController.cs
License : GNU General Public License v3.0
Project Creator : 00000vish

static void OnMachineAuth(SteamUser.UpdateMachineAuthCallback callback)
        {
            Console.WriteLine("Updating sentryfile...");

            // write out our sentry file
            // ideally we'd want to write to the filename specified in the callback
            // but then this sample would require more code to find the correct sentry file to read during logon
            // for the sake of simplicity, we'll just use "sentry.bin"

            int fileSize;
            byte[] sentryHash;
            using (var fs = File.Open("sentry.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                fs.Seek(callback.Offset, SeekOrigin.Begin);
                fs.Write(callback.Data, 0, callback.BytesToWrite);
                fileSize = (int)fs.Length;

                fs.Seek(0, SeekOrigin.Begin);
                using (var sha = SHA1.Create())
                {
                    sentryHash = sha.ComputeHash(fs);
                }
            }

            // inform the steam servers that we're accepting this sentry file
            steamUser.SendMachineAuthResponse(new SteamUser.MachineAuthDetails
            {
                JobID = callback.JobID,

                FileName = callback.FileName,

                BytesWritten = callback.BytesToWrite,
                FileSize = fileSize,
                Offset = callback.Offset,

                Result = EResult.OK,
                LastError = 0,

                OneTimePreplacedword = callback.OneTimePreplacedword,

                SentryFileHash = sentryHash,
            });

            Console.WriteLine("Done!");
        }

19 View Source File : Ribbon.cs
License : GNU General Public License v3.0
Project Creator : 0dteam

private string GetHashSha256(string filename)
        {
            using (FileStream stream = File.OpenRead(filename))
            {
                SHA256Managed sha = new SHA256Managed();
                byte[] shaHash = sha.ComputeHash(stream);
                string result = "";
                foreach (byte b in shaHash) result += b.ToString("x2");
                return result;
            }
        }

19 View Source File : OKCoinAPI.cs
License : MIT License
Project Creator : aabiryukov

private static string GetSignature(NameValueDictionary args, string secretKey)
	    {
		    var sb = new StringBuilder();
			foreach (var arg in args)
			{
				sb.Append(arg.Key);
				sb.Append("=");
				sb.Append(arg.Value);
				sb.Append("&");
			}

			sb.Append("secret_key=");
		    sb.Append(secretKey);

		    using (var md = MD5.Create())
		    {
				using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(sb.ToString())))
		        {
			        var hashData = md.ComputeHash(stream);

					// Format as hexadecimal string.
					var hashBuilder = new StringBuilder();
					foreach (byte data in hashData)
					{
						hashBuilder.Append(data.ToString("x2", CultureInfo.InvariantCulture));
					}
					return hashBuilder.ToString().ToUpperInvariant();
		        }
		    }
	    }

19 View Source File : RSACryption.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public bool GetHash(FileStream objFile, ref byte[] HashData)
        {
            //从文件中取得Hash描述 
            HashAlgorithm MD5 = HashAlgorithm.Create("MD5");
            HashData = MD5.ComputeHash(objFile);
            objFile.Close();

            return true;
        }

19 View Source File : FileHelper.cs
License : BSD 3-Clause "New" or "Revised" License
Project Creator : anoyetta

public static string GetMD5(
            string file)
        {
            var hash = string.Empty;

            using (var md5 = MD5.Create())
            {
                using (var fs = new FileStream(file, System.IO.FileMode.Open, FileAccess.Read))
                {
                    var bytes = md5.ComputeHash(fs);
                    hash = System.BitConverter.ToString(bytes).ToUpper().Replace("-", string.Empty);
                }
            }

            return hash;
        }

See More Examples