【问题标题】:VB Type setting for a SHA512 hash用于 SHA512 哈希的 VB 类型设置
【发布时间】:2011-09-19 09:19:02
【问题描述】:

我有以下用于生成 sha512 哈希的函数。哈希生成成功,但将结果字符串传递给其他函数时导致此错误:

输入的字符串格式不正确

在调试时,保存返回哈希(设置为字符串)的变量为空。我尝试在函数和调用代码中将类型更改为 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 函数也已经过检查 - 它可以完美运行并返回一个随机整数,以字符串形式返回以供说服

【问题讨论】:

    标签: vb.net types type-conversion


    【解决方案1】:

    固定为:

    函数 create_hash(ByVal 密码, 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)

    改变

    【讨论】:

      猜你喜欢
      • 2018-12-03
      • 1970-01-01
      • 1970-01-01
      • 2018-06-07
      • 2015-01-04
      • 2016-12-31
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      相关资源
      最近更新 更多