Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txt1() As Byte
txt1 = System.Text.ASCIIEncoding.ASCII.GetBytes(TextBox1.Text)
'读取输入的文字,即要加密的文字。
Dim key(16) As Byte
key = System.Text.ASCIIEncoding.ASCII.GetBytes(TextBox2.Text)'读取密钥
'HMACSHA加密
Dim hma As New System.Security.Cryptography.HMACSHA1(key)'声明加密类,既使用何种加密方法
Dim csstream As New System.Security.Cryptography.CryptoStream(System.IO.Stream.Null, hma, Security.Cryptography.CryptoStreamMode.Write)'进行加密转换
csstream.Write(txt1, 0, txt1.Length)
'将加密后的数据保存在TXT1这个变量中
'此时的txt1已经不是先前的要加密的文字,而是被刷新后的已经加密的数据。
csstream.Close()
TextBox3.Text = System.Text.ASCIIEncoding.ASCII.GetString(hma.Hash)'显示加密的文字。
End Sub