【问题标题】:VBScript error 5 trying to compute sha512 with 'System.Security.Cryptography.SHA512Managed'VBScript 错误 5 尝试使用“System.Security.Cryptography.SHA512Managed”计算 sha512
【发布时间】:2017-10-06 19:47:21
【问题描述】:

我正在尝试用 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

【问题讨论】:

  • bar 正在引用您正在运行的脚本。引用未使用的文件时是否遇到同样的错误?

标签: vbscript sha512


【解决方案1】:

使用

hsh = scs.ComputeHash_2((bar))

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

here

【讨论】:

  • 非常感谢,谢谢 beaucoup Ekkehard。它工作正常。
  • 再次感谢您的链接。指向的代码清醒、清晰、高效。
猜你喜欢
  • 2013-11-17
  • 2018-06-07
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多