doucang8303 2013-08-06 19:55
浏览 56

VB.net + mySQL + md5哈希建议

Sorry if this has already been answered. I looked but could not find anything specific.

I am writing a program in VB.NET that shares a login with an internet forum using IP Board 3.4.5.

I am having difficulty with the password part - the forum uses an md5 hash with a 4 character salt. The documentation expresses it in PHP as follows:

$hash = md5( md5( $salt ) . md5( $password ) );

I need to reach the same result using VB.NET, would anyone be able to give me a pointer as to how to achieve this?

  • 写回答

1条回答 默认 最新

  • doufei4418 2013-08-07 00:16
    关注

    While I'm not familiar with how salts are supposed to work, I've created a function that hashes a password and a salt, then uses them as input to create the final hash.

    You'll need these:

    Imports System.Security.Cryptography
    Imports System.Text
    Imports System.IO
    

    To run this:

    Private Function CreateMD5(password As String, salt As String) As String
        Dim passwordBytes() As Byte = Encoding.UTF8.GetBytes(password)
        Dim saltBytes() As Byte = Encoding.UTF8.GetBytes(salt)
        Dim saltedPasswordHash As Byte()
    
        Dim md5Hasher As MD5 = Security.Cryptography.MD5.Create()
        Dim buffer As New MemoryStream
        Dim writer As New StreamWriter(buffer) With {.AutoFlush = True}
    
        Try
            writer.Write(md5Hasher.ComputeHash(passwordBytes))
            writer.Write(md5Hasher.ComputeHash(saltBytes))
            buffer.Position = 0
            saltedPasswordHash = md5Hasher.ComputeHash(buffer)
        Finally
            writer.Dispose()
            buffer.Dispose()
            md5Hasher.Dispose()
        End Try
    
        Return String.Concat(BitConverter.ToString(saltedPasswordHash).Split("-"c))
    End Function
    

    Example usage:

    Dim saltedHash As String = CreateMD5("password", "salt")
    Console.WriteLine(saltedHash)
    

    Output:

    CDA7359AB6408E7F0088CAB68470D5FE

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100