照著書本key,練習一下
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
using(FileStream fsin=File.Create("ver1.smp"))
{
byte[] buffer = new byte[256];
Random rand = new Random();
for(int x=0;x<150;x++)
{
rand.NextBytes(buffer);
fsin.Write(buffer);
}
}
File.Copy("ver1.smp", "ver2.smp", true);
string curdir = Directory.GetCurrentDirectory();
string[] files = Directory.GetFiles(curdir, "*.smp");
SHA1 sha = SHA1.Create();
foreach(string f in files)
{
using(FileStream fs=File.OpenRead(f))
{
byte[] result = sha.ComputeHash(fs);
Console.WriteLine("file {0} Hash:", Path.GetFileName(f));
StringBuilder bd = new StringBuilder();
foreach(byte b in result)
{
bd.AppendFormat("{0:X2} ", b);
}
Console.Write(bd + "\n\n");
}
}
sha.Dispose();
}
}
}
沒有留言:
張貼留言