初始化提交
仓库转移到Gitea,初始化提交,可能丢失以前的git版本日志
This commit is contained in:
40
UTS_Core/Security/MD5.vb
Normal file
40
UTS_Core/Security/MD5.vb
Normal file
@@ -0,0 +1,40 @@
|
||||
Imports System.Security.Cryptography
|
||||
Imports System.Text
|
||||
|
||||
Namespace Security
|
||||
Public Class Md5
|
||||
''' <summary>
|
||||
''' 获取字符串的MD5值
|
||||
''' </summary>
|
||||
''' <param name="str">需要求MD5的原文字符串</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function GetStringMd5(str As String) As String
|
||||
Dim md5Hasher As New MD5CryptoServiceProvider()
|
||||
Dim data As Byte() = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(str))
|
||||
Dim fileMd5 As New StringBuilder()
|
||||
Dim i As Integer
|
||||
For i = 0 To data.Length - 1
|
||||
fileMd5.Append(data(i).ToString("X2"))
|
||||
Next
|
||||
|
||||
Return fileMd5.ToString()
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 获取文件的MD5值
|
||||
''' </summary>
|
||||
''' <param name="filepath">文件路径</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function GetFileMd5(filepath As String) As String
|
||||
Dim md5Hasher As New MD5CryptoServiceProvider()
|
||||
Dim data As Byte() = md5Hasher.ComputeHash(IO.File.ReadAllBytes(filepath))
|
||||
Dim fileMd5 As New StringBuilder()
|
||||
Dim i As Integer
|
||||
For i = 0 To data.Length - 1
|
||||
fileMd5.Append(data(i).ToString("X2"))
|
||||
Next
|
||||
|
||||
Return fileMd5.ToString()
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user