gpt4 book ai didi

vba - 从 VBA 调用 .NET 加密

转载 作者:行者123 更新时间:2023-12-01 22:33:42 24 4
gpt4 key购买 nike

我正在尝试在 VBA 中生成 SHA-1 哈希(我不是很熟悉)。在 .NET 中,它非常简单,使用 System.Security.Cryptography。一种方法如下:

using System.Security.Cryptography;
...

byte[] data;
// fill data here
SHA1Managed sha = new SHA1Managed();
bytes[] hash = sha.ComputeHash(data);

您将如何从 VBA 中调用它?我做到了这一点

Dim oSHA As Object
Set oSHA = CreateObject("System.Security.Cryptography.SHA1Managed")

但我不知道如何将 Byte 数组传递给 ComputeHash

hash = oSHA.ComputeHash(oBytes)

这会引发有关参数不正确的错误。如何将其转换为 .NET 接受的格式?

请注意,我不想对 SHA-1 使用 VBA 计算(太慢了,我不想重新发明轮子)。如果我不必为 .NET 部分编写任何包装器,那也很好。

最佳答案

来自System.Security.Cryptography.HashAlgorithm:

  • ComputeHash_1(inputStream As stream)
  • ComputeHash_2(buffer As byte())
  • ComputeHash_3(buffer As byte(),offset As int,count As int)

关于vba - 从 VBA 调用 .NET 加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28325067/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com