我正在尝试在 VBA (Excel 2003) 上计算字符串的哈希值,但是当我调用 时ComputeHash
,它会抛出一个Invalid argument/procedure call
错误。
DLL 参考:mscorlib v4.0、System v4.0
MSDN 参考:http: //msdn.microsoft.com/en-us/library/system.security.cryptography.sha512managed.aspx
Sub Main()
Dim instance As New SHA512Managed
Dim data() As Byte
data = StringToByte("mymsg")
Dim result() As Byte
instance.ComputeHash(data) 'Throws runtime error'
MsgBox (ByteToString(result))
End Sub
Function StringToByte(ByVal s)
Dim b() As Byte
b = s 'Assign Unicode string to bytes.'
StringToByte = b
End Function
Function ByteToString(ByVal dBytes)
Dim strText As String
strText = dBytes
ByteToString = strText
End Function