| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolset.Core.Burn.Bundles |
| 4 | { |
| 5 | using System.IO; |
| 6 | using System.Security.Cryptography; |
| 7 | using System.Text; |
| 8 | |
| 9 | internal static class BundleHashAlgorithm |
| 10 | { |
| 11 | public static string Hash(FileInfo fileInfo) |
| 12 | { |
| 13 | byte[] hashBytes; |
| 14 | |
| 15 | using (var managed = new SHA512CryptoServiceProvider()) |
| 16 | using (var stream = fileInfo.OpenRead()) |
| 17 | { |
| 18 | hashBytes = managed.ComputeHash(stream); |
| 19 | } |
| 20 | |
| 21 | var sb = new StringBuilder(hashBytes.Length * 2); |
| 22 | for (var i = 0; i < hashBytes.Length; i++) |
| 23 | { |
| 24 | sb.AppendFormat("{0:X2}", hashBytes[i]); |
| 25 | } |
| 26 | |
| 27 | return sb.ToString(); |
| 28 | } |
| 29 | } |
| 30 | } |