开发者

VB Type setting for a SHA512 hash

I have the following function for generating sha512 hashs. The hash is generated successfully, but is causing this error when the resulting string is passed to other functions:

Input string was not in a correct format

When debugged the variable holding the returned hash (set as string) is empty. I have tried changing the type to int, int64 and byte (array and standard variable) in the function and in the calling code, which causes various other errors. How can I change the datatype correctly to solve this?

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

Calling code:

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))

edit:

the create_salt function has also been checked - it works perfectly and returns a random integer, returned as string for conveince


Fixed with:

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 = BitConverter.ToString(result)
    Return return_result
End Function

Dim return_result As String = BitConverter.ToString(result)

Being the change

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜