我想通过Excel VBA将API与Excel连接。 API需要具有RSA-SHA1签名的公钥/私钥对。我使用openssl生成该对,将公钥上传到API的服务,并将私有部分存储在我的本地计算机上。
现在我想连接我的API,以便签署我的请求。但是VBA没有本机RSA-SHA1签名。我在https://en.wikibooks.org/wiki/Visual_Basic_for_Applications/String_Hashing_in_VBA找到了以下代码,它在.net的帮助下签署了一条消息,但我无法提供私钥。
Public Function SHA1(sIn As String, Optional bB64 As Boolean = 0) As String
'Set a reference to mscorlib 4.0 64-bit
'Test with empty string input:
'40 Hex: da39a3ee5e6...etc
'28 Base-64: 2jmj7l5rSw0yVb...etc
Dim oT As Object, oSHA1 As Object
Dim TextToHash() As Byte
Dim bytes() As Byte
Set oT = CreateObject("System.Text.UTF8Encoding")
Set oSHA1 = CreateObject("System.Security.Cryptography.SHA1Managed")
TextToHash = oT.GetBytes_4(sIn)
bytes = oSHA1.ComputeHash_2((TextToHash))
If bB64 = True Then
SHA1 = ConvToBase64String(bytes)
Else
SHA1 = ConvToHexString(bytes)
End If
Set oT = Nothing
Set oSHA1 = Nothing
End Function
我可以通过密钥(遵循良好做法)从VBA使用RSA-SHA1签署哪些方法,前提是我已准备好密钥并且只需要加载?