格式化文本输出来自Stream

时间:2016-10-31 20:46:08

标签: vb.net sha1

我正在尝试生成一个“签名”SHA1字符串以附加到URI。

我有一个字符串URI片段和来自目标供应商的秘密。我需要获取URI文本和密码,并在格式化中生成一个与此类似的签名字符串:“4623B7B8-18A6-4B2C-B2C1-18157F5C4AFE”

Imports System.Security.Cryptography

'This is the String to use to create the SHA1
Dim DataToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text)
'This is the secret key given to me from the vendor
Dim SecretKey() As Byte = System.Text.Encoding.ASCII.GetBytes(TextBox2.Text)
    Using myhmac As New HMACSHA1(SecretKey)
         Using MS As New IO.MemoryStream(DataToHash)
              Dim HashValue As Byte() = myhmac.ComputeHash(MS)
              'This is the output or signature
              TextBox3.Text = System.Text.Encoding.Unicode.GetString(HashValue)
         End Using
    End Using

我从某人那里得到了这段代码,但输出testbox3.text看起来像中文。

enter image description here

我错过了什么?

0 个答案:

没有答案