VB.NET 2008 获取MD5加密
1 Imports System.Text
2 Imports System.Security.Cryptography
3
4 Function getMD5Hash(ByVal strToHash As String) As String
5 Dim md5Obj As New Security.Cryptography.MD5CryptoServiceProvider
6 Dim bytesToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(strToHash)
7 bytesToHash = md5Obj.ComputeHash(bytesToHash)
8 Dim strResult As String = ""
9 For Each b As Byte In bytesToHash
10 strResult += b.ToString("x2")
11 Next
12 Return strResult
13 End Function
14 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
15 If txtmm.Text <> "" Then
16 txtmd5.Text = getMD5Hash(txtmm.Text)
17 End If
18 End Sub