VBScript 错误 5 尝试使用 'System.Security.Cryptography.SHA512Managed' 计算 sha512

标签 vbscript sha512

我正在尝试用 VBScript 编写一段代码来计算 给定文件的 SHA512 值。根据 MSFT 文档 SHA512Managed 对象的 ComputeHash 方法需要 字节数组作为输入。所以我使用ADODB读取输入文件 要计算 SHA512 值(因为,AFAIK,没有办法 在 VBScript 中构建字节数组)。但是我收到运行时错误 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

最佳答案

使用

hsh = scs.ComputeHash_2((bar))

(无设置,_2后缀不挑其他ComputeHash方法,按值传递())

参见here .

关于VBScript 错误 5 尝试使用 'System.Security.Cryptography.SHA512Managed' 计算 sha512,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46612969/

相关文章:

java - Jmeter如何生成哈希sha512

iphone - 像 C# 一样使用 SHA512 对密码字符串进行哈希处理

IIS 7/Pure ASP 文件上传问题

file - 从返回的文件列表中删除文件扩展名

VBScript 自定义文本框

vbscript - VBS 使用 LIKE 比较字符串 "Sub or Function not defined"

linux - 测试命令在 vbscript 中是否输出空字符串

php - 在 Go 中生成 crypt() sha512 哈希

c - C 中 64 位架构上的 128 位值

hash - 为什么选择 SHA512 而不是 SHA384?