Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # get files MD5 and SHA1

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

The first method directly uses the FileInfo class constructor to pass in the path, because it is convenient for the console to drag and drop files directly.

It is important to note that there are spaces in the path that will report an error.

In this method, s represents the incoming file path.

1 static void GetFile (string s) 2 {3 try 4 {5 FileInfo fi = new FileInfo (s); 6 Console.WriteLine ("File path: {0}", s); 7 Console.WriteLine ("File name: {0}", fi.Name.ToString ()) 8 Console.WriteLine ("File Type: {0}", fi.Extension.ToString ()); 9 Console.WriteLine ("File size: {0} K", fi.Length / 1024); 10 Console.WriteLine ("File creation time: {0}", fi.CreationTime.ToString ()) 11 Console.WriteLine ("Last access time: {0}", fi.LastAccessTime.ToString ()); 12 Console.WriteLine ("Last write time: {0}", fi.LastWriteTime.ToString ()); 13} 14 catch (Exception ex) 15 {16 Console.WriteLine (ex.Message); 17} 18}

The second method gets the MD5 value, where s represents the incoming file path

MD5 treats the whole file as a large text message and produces this unique MD5 message summary through its irreversible string transformation algorithm.

1 static void GetMD5 (string s) 2 {3 try 4 {5 FileStream file = new FileStream; 6 MD5 md5 = new MD5CryptoServiceProvider (); 7 byte [] retval = md5.ComputeHash (file); 8 file.Close (); 9 10 StringBuilder sc = new StringBuilder () 11 for (int I = 0; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report