用例,VBA的环境是GB2312的,直接MD5中文字符出来的会与实际通用的UTF8字符数据不一致,所以要先转UTF8再MD5
Sub test() Dim f As New MD5 Dim s As String s = "中文字" Debug.Print "ANSI:" & f.DigestStrToHexStr(s) Dim a() As Byte, b() As Byte a = s Debug.Print "GB2312:" & f.DigestByteToHexStr(a) Debug.Print "GB2312-UTF8:" & f.DigestByteToHexStr(Unicode_To_UTF8(a)) '这里的数据和网上在线MD5验证网站一致。 b = StrConv(s, vbFromUnicode) Debug.Print "ANSI-UTF8:" & f.DigestByteToHexStr(Unicode_To_UTF8(b)) End Sub