如何在VB.NET中将文本加密为MD5哈希?

时间:2015-05-31 16:51:55

标签: vb.net hash md5

我想计算RichTextBox1.Text的MD5哈希值。我在顶部添加了这行代码,以便我可以使用MD5加密方法:Imports System.Security.Cryptography。我如何实际计算哈希?

1 个答案:

答案 0 :(得分:0)

该过程描述为here

链接的基本代码是:

Dim Bytes() As Byte
Dim sb As New StringBuilder() 

Bytes = Encoding.Default.GetBytes(RichTextBox1.Text)

'Get md5 hash
Bytes = MD5.Create().ComputeHash(Bytes)

'Loop though the byte array and convert each byte to hex.
For x As Integer = 0 To Bytes.Length - 1
    sb.Append(Bytes(x).ToString("x2"))
Next

'Return md5 hash.
Return sb.ToString()