1
我有以下用於生成sha512哈希的函數。散列成功生成,但是當所得到的字符串被傳遞給其他功能引起該錯誤:用於SHA512哈希的VB類型設置
輸入字符串的不正確的格式
當調試的變量保持返回的散列(設置爲字符串)爲空。我試圖在函數和調用代碼中將類型更改爲int,int64和byte(數組和標準變量),這會導致各種其他錯誤。如何正確地更改數據類型來解決此問題?
Function create_hash(ByVal password, ByVal salt)
Dim salty As String = password & salt
'convert salty password to binary to feed into hash function
Dim encText As New System.Text.UTF8Encoding()
Dim btText() As Byte
btText = encText.GetBytes(salty)
'Dim data(btText) As Byte
'create password hash
Dim result() As Byte
Dim shaM As New SHA512Managed()
result = shaM.ComputeHash(btText)
Dim return_result As String
For Each Item As Integer In result
return_result = return_result & Item
Next
Return return_result
End Function
調用代碼:
Dim i_h_pass As String
Dim i_pass As String = pass.Text
'handle password generation (matching passwords checked at validation)
Dim newHash = New hashing
Dim salt As String = Convert.ToString(newHash.create_salt)
i_h_pass = Convert.ToString(newHash.create_hash(i_pass, salt))
編輯:
的create_salt功能也得到了確認 - 它完美的作品,並返回一個隨機整數,返回字符串conveince