实施 PBKDF2
Implementing PBKDF2
我一直在构建一个自定义访问数据库,并且添加了一个带有用户名和密码的登录屏幕。最初我使用 SHA1 并且没有加盐来散列密码。 (我知道这不是很安全,但它只适用于少数用户并且不包含任何个人信息)
但是公司已经看到了数据库应用程序,他们想要安装它并添加更多用户和功能。我想开始使用 Salts 和 PBKDF2 来获取密码,但我找不到任何关于 PBKDF2 的信息,特别是在 MS Acess 中。以下是我拼凑的 2 个函数
Public Function PBKDF2(pass As String, salt As String, inter As Int32) As String
Set oT = CreateObject("System.Text.UTF8Encoding")
Dim bytes() As Byte
TextToHash = oT.GetBytes_4((pass))
SaltBytes = oT.GetBytes_4((salt))
Set oRFC = CreateObject("System.Security.Cryptography.Rfc2898DeriveBytes( (TextToHash), (SaltBytes), inter )")
bytes() = oRFC.GetBytes(16)
PBKDF2 = ByteArrayToHex(bytes())
End Function
Private Function ByteArrayToHex(ByRef ByteArray() As Byte) As String
Dim lb As Long, ub As Long
Dim l As Long, strRet As String
Dim lonRetLen As Long, lonPos As Long
Dim strHex As String, lonLenHex As Long
lb = LBound(ByteArray)
ub = UBound(ByteArray)
lonRetLen = ((ub - lb) + 1) * 3
strRet = Space$(lonRetLen)
lonPos = 1
For l = lb To ub
strHex = Hex$(ByteArray(l))
If Len(strHex) = 1 Then
strHex = "0" & strHex
End If
If l <> ub Then
Mid$(strRet, lonPos, 3) = strHex & " "
lonPos = lonPos + 3
Else
Mid$(strRet, lonPos, 3) = strHex
End If
Next l
ByteArrayToHex = strRet
End Function
我收到错误
"ByRef argument mismatch"
是否有更好的方法在 Access 中实现 PBKDF2 VBA,或者是否有针对这些功能的修复?
@zaph 和@EricvonAsmuth 都有有效分数。看来Rfc2898DeriveBytes
不能直接用在VBA中。尝试其他路径可能更简单。
您可以在线找到本机 VB6/VBA SHA1 实现。您可以针对在线 SHA1 生成器测试这些以验证有效性。
根据您对 .NET 和 COM 的熟悉程度,此方法可能更简单。
我一直在构建一个自定义访问数据库,并且添加了一个带有用户名和密码的登录屏幕。最初我使用 SHA1 并且没有加盐来散列密码。 (我知道这不是很安全,但它只适用于少数用户并且不包含任何个人信息)
但是公司已经看到了数据库应用程序,他们想要安装它并添加更多用户和功能。我想开始使用 Salts 和 PBKDF2 来获取密码,但我找不到任何关于 PBKDF2 的信息,特别是在 MS Acess 中。以下是我拼凑的 2 个函数
Public Function PBKDF2(pass As String, salt As String, inter As Int32) As String
Set oT = CreateObject("System.Text.UTF8Encoding")
Dim bytes() As Byte
TextToHash = oT.GetBytes_4((pass))
SaltBytes = oT.GetBytes_4((salt))
Set oRFC = CreateObject("System.Security.Cryptography.Rfc2898DeriveBytes( (TextToHash), (SaltBytes), inter )")
bytes() = oRFC.GetBytes(16)
PBKDF2 = ByteArrayToHex(bytes())
End Function
Private Function ByteArrayToHex(ByRef ByteArray() As Byte) As String
Dim lb As Long, ub As Long
Dim l As Long, strRet As String
Dim lonRetLen As Long, lonPos As Long
Dim strHex As String, lonLenHex As Long
lb = LBound(ByteArray)
ub = UBound(ByteArray)
lonRetLen = ((ub - lb) + 1) * 3
strRet = Space$(lonRetLen)
lonPos = 1
For l = lb To ub
strHex = Hex$(ByteArray(l))
If Len(strHex) = 1 Then
strHex = "0" & strHex
End If
If l <> ub Then
Mid$(strRet, lonPos, 3) = strHex & " "
lonPos = lonPos + 3
Else
Mid$(strRet, lonPos, 3) = strHex
End If
Next l
ByteArrayToHex = strRet
End Function
我收到错误
"ByRef argument mismatch"
是否有更好的方法在 Access 中实现 PBKDF2 VBA,或者是否有针对这些功能的修复?
@zaph 和@EricvonAsmuth 都有有效分数。看来Rfc2898DeriveBytes
不能直接用在VBA中。尝试其他路径可能更简单。
您可以在线找到本机 VB6/VBA SHA1 实现。您可以针对在线 SHA1 生成器测试这些以验证有效性。
根据您对 .NET 和 COM 的熟悉程度,此方法可能更简单。