반응형
[C#] Get HashString, from File Strem

 

파일스트림의 고유한 해쉬값 추출하는 내용

 

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string fileName = @"c:\1.tif";

            MessageBox.Show(GetChecksum(fileName));

        }
        public static string GetChecksum(string sPathFile)
        {
            if (!File.Exists(sPathFile))
                return null;

            using (FileStream stream = File.OpenRead(sPathFile))
            {
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] byteChecksum = md5.ComputeHash(stream);
                return BitConverter.ToString(byteChecksum).Replace("-", String.Empty);
            }
        }
    }
}

반응형
Posted by Rainfly
l