Imports System.Security.Cryptography
Imports System.Text
Public Class getmd5
Public Function getmd5hash(ByVal md5Hash As MD5, ByVal input As String) As String
Dim data As Byte() = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input))
Dim sBuilder As New StringBuilder()
Dim i As Integer
For i = 0 To data.Length - 1
sBuilder.Append(data(i).ToString("x2"))
Next i
Return sBuilder.ToString()
End Function
End Class
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Try
Dim bc_getmd5 As New getmd5
Dim source As String = tbdtefolioclave.Text.Trim
Dim hash As String = ""
Using md5hash As MD5 = MD5.Create()
hash = bc_getmd5.getmd5hash(md5hash, source)
End Using
tbmd5.Text = hash
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Ejemplo2
'dte+folio+clave
Dim source As String = "33" & "123" & "123456"
Dim hash As String = getHashMd5(source) 'Resultado: 2492f78aa4119e8d5c545ce9006f56b1
Public Function getHashMd5(ByVal stringSource As String) As String
Using md5hash As MD5 = MD5.Create
Dim data As Byte() = md5hash.ComputeHash(Encoding.UTF8.GetBytes(stringSource))
Dim sBuilder As New StringBuilder()
Dim i As Integer
For i = 0 To data.Length - 1
sBuilder.Append(data(i).ToString("x2"))
Next i
Return sBuilder.ToString()
End Using
End Function
fuente
No hay comentarios.:
Publicar un comentario