我在我的 vb 應用程式中從這里使用這個 scrypt
我試過這個代碼來散列一個十六進制字串:
Imports Replicon.Cryptography.SCrypt
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ss() As Byte = System.Text.Encoding.Default.GetBytes(TextBox1.Text)
RichTextBox1.Text = System.Text.Encoding.Default.GetString(SCrypt.DeriveKey(ss, ss, 1024, 1, 1, 32))
End Sub
End Class
文本框內的十六進制字串:
TextBox1.text = "01000000f615f7ce3b4fc6b8f61e8f89aedb1d0852507650533a9e3b10b9bbcc30639f279fcaa86746e1ef52d3edb3c4ad8259920d509bd073605c9bf1d59983752a6b06b817bb4ea78e011d012d59d4"
它給了我這個:
r3?<??h??-$:8′"y?P °? W?&‰?
反轉小端后的預期結果是這樣的:
0000000110c8357966576df46f3b802ca897deb7ad18b12f1c24ecff6386ebd9
我想問題是位元組轉換,字串轉換?
幫助表示贊賞
謝謝大家。
uj5u.com熱心網友回復:
我找到了解決方案:
代碼是:
Imports Replicon.Cryptography.SCrypt
Imports System.Globalization
Imports System.Text
Public Class Form1
Public Shared Function Btog(ByVal ba() As Byte) As String
Dim hex As StringBuilder = New StringBuilder(ba.Length * 2)
Dim b As Byte
For Each b In ba
hex.AppendFormat("{0:x2}", b)
Next
Return hex.ToString()
End Function
Public Function HexDecode(ByVal s As String) As Byte()
Return HexDecode(s, 0)
End Function
Public Function HexDecode(ByVal s As String, ByVal paddingBytes As Integer) As Byte()
If s Is Nothing Then
Throw New ArgumentNullException("s")
End If
If s.IndexOf(":"c) > -1 Then
s = s.Replace(":", "")
End If
If (s.Length Mod 2) <> 0 Then
Throw New FormatException("parameter 's' must have an even number of hex characters")
End If
Dim result As Byte() = New Byte(s.Length \ 2 (paddingBytes - 1)) {}
For i As Integer = 0 To result.Length - paddingBytes - 1
result(i) = Byte.Parse(s.Substring(i * 2, 2), NumberStyles.AllowHexSpecifier)
Next
Return result
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
RichTextBox1.Text = Btog(SCrypt.DeriveKey(HexDecode(TextBox1.Text), HexDecode(TextBox1.Text), 1024, 1, 1, 32))
End Sub
End Class
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/393726.html
