첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

TestProject.zip
0.00MB

▶ Program.cs

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace TestProject
{
    /// <summary>
    /// 프로그램
    /// </summary>
    class Program
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region SHA256 해시 문자열 구하기 - GetSHA256HashString(filePath)

        /// <summary>
        /// SHA256 해시 문자열 구하기
        /// </summary>
        /// <param name="filePath">파일 경로</param>
        /// <returns>SHA256 해시 문자열</returns>
        private static string GetSHA256HashString(string filePath)
        {
            SHA256 sha256 = new SHA256Managed();

            StringBuilder stringBuilder = new StringBuilder();

            using(FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                byte[] hashByteArray = sha256.ComputeHash(fileStream);

                foreach(byte hashByte in hashByteArray)
                {
                    stringBuilder.Append(hashByte.ToString("X2"));
                }
            }

            return stringBuilder.ToString();
        }

        #endregion
        #region MD5 해시 문자열 구하기 - GetMD5HashString(filePath)

        /// <summary>
        /// MD5 해시 문자열 구하기
        /// </summary>
        /// <param name="filePath">파일 경로</param>
        /// <returns>MD5 해시 문자열</returns>
        private static string GetMD5HashString(string filePath)
        {
            MD5 md5 = MD5.Create();

            StringBuilder stringBuilder = new StringBuilder();

            using(FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                byte[] hashByteArray = md5.ComputeHash(fileStream);

                foreach(byte hashByte in hashByteArray)
                {
                    stringBuilder.Append(hashByte.ToString("x2"));
                }
            }

            return stringBuilder.ToString();
        }

        #endregion

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        private static void Main()
        {
            string filePath = "d:\\TestProject.exe";

            string deploymentVersion = "V1.0.0";
            string name              = "TestProject";
            string programName       = "TestProject.exe";
            string productVersion    = "1.0.0.0";
            string serverIPAddress   = "127.0.0.1";
            int    serverPort        = 8000;
            string url               = $"http://{serverIPAddress}:{serverPort}/download/{deploymentVersion}/{programName}";
            long   size              = new FileInfo(filePath).Length;
            string sha256            = GetSHA256HashString(filePath);
            string md5               = GetMD5HashString(filePath);
            string serverFileName    = programName;
            string registryKey       = @"HKUD\Software\DSCore\TestProject\Version";
            string version           = productVersion;
            string description       = deploymentVersion;

            string meta = $@"[{deploymentVersion}]
Name = {name}
ProductVersion = {productVersion}
URL = {url}
Size = {size}
SHA256 = {sha256}
MD5 = {md5}
ServerFileName = {serverFileName}
RegistryKey = {registryKey}
Version = {version}
Description = {description}";

            Console.WriteLine(meta);
        }

        #endregion
    }
}
728x90
그리드형(광고전용)
Posted by icodebroker
,