首页  编辑  

计算字符串和文件MD5值

Tags: /C#/字符串处理/   Date Created:

using System . Security . Cryptography;

MD5 vMD5 = MD5 . Create();

byte [] vBuffer = Encoding . Default . GetBytes( "Zswang" );

Text = BitConverter . ToString(vMD5 . ComputeHash(vBuffer));

// or

MD5 vMD5 = MD5 . Create();

FileStream vFileStream = new FileStream ( @"c:\temp\temp.txt" ,

    FileMode . Open, FileAccess . Read);

Text = BitConverter . ToString(vMD5 . ComputeHash(vFileStream));

vFileStream . Close();