虽然我并不熟悉盐应该如何工作,但我创建了一个函数,其中包含密码和盐,然后将它们用作输入来创建最终的哈希。
你需要这些:
Imports System.Security.Cryptography
Imports System.Text
Imports System.IO
要运行此:
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
用法示例:
Dim saltedHash As String = CreateMD5("password", "salt")
Console.WriteLine(saltedHash)
输出:
CDA7359AB6408E7F0088CAB68470D5FE
从哪里得到盐?它是存储在数据库字段中的随机盐 – Orangepill
使用[本指南]可能需要为ipboard实施您自己的登录适配器(http://www.invisionpower.com/support/guides/_/advanced-and-developers/整合/登录模块-R42) – Orangepill