I'm trying to compute the hash of a string on VBA (Excel 2003), but when I call ComputeHash
, it throws me an Invalid argument/procedure call
error.
DLL References: mscorlib v4.0, System v4.0
MSDN reference: 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