我有一个Web服务加载驱动程序,它是一个Windows脚本文件(WSF),包括一些VBScript和JavaScript文件.我的Web服务要求传入的消息是base64编码的.我目前有一个VBScript函数可以做到这一点,但效率很低(内存密集,主要是由于VBScripts可怕的字符串连接)
[在旁边; 是的,我见过杰夫的最新博文.串联发生在跨越1,000到10,000字节大小的消息的循环中.
我尝试过使用一些自定义字符串连接例程; 一个使用数组,一个使用ADODB.Stream.这些帮助,一点点,但我认为如果我有其他方式编码消息而不是通过我自己的VBS功能,它会有所帮助.
有没有其他方式编码我的消息,优先使用本机Windows方法?
我有一个代码可以从需要凭据的网站下载 CSV 文件。感谢这个网站,我得到了一个代码,我可以适应我的需求。我的相关代码部分是:
Option Explicit
Private Declare Function URLDownloadToFileA Lib "urlmon" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Function DownloadUrlFile(URL As String, LocalFilename As String) As Boolean
Dim RetVal As Long
RetVal = URLDownloadToFileA(0, URL, LocalFilename, 0, 0)
If RetVal = 0 Then DownloadUrlFile = True
End Function
Sub DESCARGAR_CSV_DATOS()
Dim EstaURL As String
Dim EsteCSV As String
EstaURL …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Base64将图像插入到使用VBA的工作表中,但我找不到任何在任何地方正确执行此操作的示例.
我有一个图像的字符串设置,如:
vLogo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZoAAABfCAY"
我只是想做以下事情,但不是寻找图像文件存储VBA中的图像.
Sheets("Sheet1").Pictures.Insert (Application.ActiveWorkbook.Path & "\vLogo.png")
我甚至看过这样的事情:
' Write the image to file
Dim myFile As String
myFile = Application.ActiveWorkbook.Path & "\temp.png"
Open myFile For Output As #1
Write #1, vLogo
Close #1
' Insert the image
Sheets("Sheet1").Pictures.Insert (Application.ActiveWorkbook.Path & "\temp.png")
' Delete the temp file
Kill Application.ActiveWorkbook.Path & "\temp.png"
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何将base64编码的图像写入文件.
也许我疯了,但看起来在 VB 中运行 Base64 的著名代码在第 73 个位置插入了一个换行符 (ascii 10),这随后使编码的字符串对于基本身份验证或其他任何与此相关的内容无效。
原始代码:
Function Stream_StringToBinary(Text)
Const adTypeText = 2
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
BinaryStream.CharSet = "us-ascii"
'Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.WriteText Text
'Change stream type To binary
BinaryStream.Position = 0
BinaryStream.Type = adTypeBinary …Run Code Online (Sandbox Code Playgroud) 我需要将Excel(或通过VBA)中的图像转换为base64(最后我将生成XML输出).
我怎样才能做到这一点?我是否需要引用DOM?
我一直在读这个问题,但它只适用于文字字符串而不是图像......
有没有人有我能看到的代码?
我正在尝试将ASP/VBScript OAuth库转换为VBA.其中一个挑战是这行代码:
Get_Signature = b64_hmac_sha1(strSecret, strBaseSignature)
Run Code Online (Sandbox Code Playgroud)
该函数b64_hmac_sha1实际上是JavaScript库中包含的函数.在我看来,从VBA调用JavaScript函数是相当不切实际的.
因为我对加密知之甚少,所以我甚至不清楚这个b64_hmac_sha1功能是做什么的.HMAC SHA1与SHA1不同吗?
我怀疑我可以在网上找到一些VBA代码来做我需要做的事情,如果我只是理解这个功能实际上在做什么.如果我找不到现有的函数,我可能会编写一个使用.NET Cryptography库的函数(如果你知道如何,你可以从VBA调用.NET加密库).
我不是在找人将这个JavaScript转换为VBA.我只是想了解这个b64_hmac_sha1函数输出的是什么,所以我可以尝试找到在VBA中实现相同输出的方法(如果可能的话).
此网站上提供了此JavaScript库的副本.您必须向下滚动浏览VBScript到JavaScript部分. http://solstice.washington.edu/solstice/ASP_Signing_REST_Example
编辑1:
好的,所以这里是我写完和使用的函数:
Public Function Base64_HMACSHA1(ByVal sTextToHash As String, ByVal sSharedSecretKey As String)
Dim asc As Object, enc As Object
Dim TextToHash() As Byte
Dim SharedSecretKey() As Byte
Set asc = CreateObject("System.Text.UTF8Encoding")
Set enc = CreateObject("System.Security.Cryptography.HMACSHA1")
TextToHash = asc.Getbytes_4(sTextToHash)
SharedSecretKey = asc.Getbytes_4(sSharedSecretKey)
enc.Key = SharedSecretKey
Dim bytes() As Byte
bytes = enc.ComputeHash_2((TextToHash))
Base64_HMACSHA1 = EncodeBase64(bytes)
Set asc = Nothing
Set enc = Nothing
End Function
Private Function …Run Code Online (Sandbox Code Playgroud)