我已经构建了一个定制的access DB,并添加了一个带有用户名和密码的登录屏幕。最初,我使用SHA1而不是salt来散列密码。(我知道这不是很安全,但它只针对少数用户,不包含任何个人信息)
然而,公司已经看到了DB应用程序,他们希望安装它,并添加更多的用户和功能。我想开始使用Salts和PBKDF2来获得密码,但是我没有找到任何关于PBKDF2的信息,特别是使用MS。下面是我拼凑在一起的两个功能
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参数错配“
在Access VBA中是否有更好的实现PBKDF2的方法,或者这些函数是否有修复?
发布于 2018-03-23 21:02:05
@zaph和@EricvonAsmuth都有有效的点。看来Rfc2898DeriveBytes不能直接在VBA中使用。尝试另一条路径可能更简单。
有一些本地VB6/VBA SHA1实现,您可以在网上找到。您可以在联机SHA1生成器上测试这些生成器以验证有效性。
根据您对.NET和COM的舒适度,这种方法可能更容易。
https://stackoverflow.com/questions/49413844
复制相似问题