vb.net怎么计算文件的md5值
如题,谢谢各位大佬!
''' <summary>
''' 获取本地文件的MD5值
''' </summary>
''' <param name="strSource">文件地址</param>
''' <returns>文件的MD5</returns>
''' <remarks></remarks>
Public Shared Function getMD5(ByVal strSource As String) As String
Dim result As String = ""
Try
Dim fstream As New FileStream(strSource, FileMode.Open, FileAccess.Read)
Dim dataToHash(fstream.Length - 1) As Byte
fstream.Read(dataToHash, 0, fstream.Length)
fstream.Close()
Dim hashvalue As Byte() = CType(CryptoConfig.CreateFromName("MD5"), HashAlgorithm).ComputeHash(dataToHash)
Dim i As Integer
For i = 0 To hashvalue.Length - 1
result += Microsoft.VisualBasic.Right("00" + Hex(hashvalue(i)).ToLower, 2)
Next
Return result
Catch ex As Exception
Return ex.Message
End Try
End Function