注册 登录
编程论坛 VB.NET论坛

vb.net怎么计算文件的md5值

古123 发布于 2019-08-02 12:05, 2883 次点击
如题,谢谢各位大佬!
2 回复
#2
yanzhu63562019-08-12 11:25
''' <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
#3
古1232019-08-18 20:25
回复 2楼 yanzhu6356
谢谢,抱歉,发帖时忘记了写积分,我重新发一个贴,你随便回复些,结贴时,我给你20积分,非常抱歉!
1