aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.Burn/Bundles/BundleHashAlgorithm.cs
blob: 3b4a4156fd4677121ba1b5d34f674b15f5cf8050 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 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.

namespace WixToolset.Core.Burn.Bundles
{
    using System.IO;
    using System.Security.Cryptography;
    using System.Text;

    internal static class BundleHashAlgorithm
    {
        public static string Hash(FileInfo fileInfo)
        {
            byte[] hashBytes;

            using (var managed = new SHA512CryptoServiceProvider())
            using (var stream = fileInfo.OpenRead())
            {
                hashBytes = managed.ComputeHash(stream);
            }

            var sb = new StringBuilder(hashBytes.Length * 2);
            for (var i = 0; i < hashBytes.Length; i++)
            {
                sb.AppendFormat("{0:X2}", hashBytes[i]);
            }

            return sb.ToString();
        }
    }
}