我正在尝试在VBScript中编写一段代码来计算 给定文件的SHA512值。根据MSFT文档 SHA512Managed对象的ComputeHash方法需要一个 字节数组作为输入。所以我用ADODB来读取输入文件 要计算SHA512值(因为,AFAIK,没有办法 在VBScript中构建一个Byte数组。但是我收到运行时错误5, 调用方法时,“无效的过程调用或参数”。该 下面代码中的变量bar是Byte()类型 - VBScript说。
有谁能告诉我出了什么问题?
代码:
Option Explicit
'
'
'
Dim scs, ado
Dim bar, hsh
Set scs = CreateObject("System.Security.Cryptography.SHA512Managed")
Set ado = CreateObject("ADODB.Stream")
ado.type = 1 ' TypeBinary
ado.open
ado.LoadFromFile WScript.ScriptFullName
bar = ado.Read
ado.Close
MsgBox TypeName(bar) & "/" & LenB(bar) & "/" & Len(bar),,"Box 1"
' Displays : "Byte()/876/438"
On Error Resume Next
' Attempt 1
Set hsh = scs.ComputeHash(bar)
MsgBox Hex(Err.Number) & "/" & Err.Description,,"Set hsh = "
' Displays : "5/Invalid procedure call or argument"
' Attempt 2
hsh = scs.ComputeHash(bar)
MsgBox Hex(Err.Number) & "/" & Err.Description,,"hsh = "
' Displays : "5/Invalid procedure call or argument"
MsgBox TypeName(scs),,"scs" ' Displays : "SHA512Managed"
Set ado = Nothing
Set scs = Nothing
WScript.Quit