CNV_BytesFromB64Str decodes a base64-encoded string into an array of Bytes.
Public Declare Function CNV_BytesFromB64Str Lib "diCryptoSys.dll"
(ByRef abData As Byte, ByVal nDataLen As Long, ByVal strInput As String) As Long
nLen = CNV_BytesFromB64Str(abData(0), nDataLen, strInput)
Byte array suitably dimensioned to receive output.Long specifying the length of the byte array.String of base64 data to be decoded.
long _stdcall CNV_BytesFromB64Str(unsigned char *output, long out_len, const char *input);
Long: If successful, the return value is the number of bytes in the decoded array;
otherwise it returns a negative error code.
Use the in-built method System.Convert.FromBase64String.
Call the function with an empty array to find the required length. Non-base64 characters in the input string are ignored.
Public Function cnvBytesFromB64Str(strB64 As String) As Variant ' Returns a Variant to an array of bytes decoded from a base64 string Dim abData() As Byte Dim nDataLen As Long ' Set default return value that won't cause a run-time error cnvBytesFromB64Str = StrConv("", vbFromUnicode) nDataLen = CNV_BytesFromB64Str(0, 0, strB64) If nDataLen <= 0 Then Exit Function End If ReDim abData(nDataLen - 1) nDataLen = CNV_BytesFromB64Str(abData(0), nDataLen, strB64) If nDataLen <= 0 Then Exit Function End If ReDim Preserve abData(nDataLen - 1) cnvBytesFromB64Str = abData End Function
Dim strBase64 As String
Dim abData() As Byte
Dim i As Integer
strBase64 = "/ty6mHZUMhA="
' Convert base64 string to bytes
abData = cnvBytesFromB64Str(strBase64)
For i = LBound(abData) To UBound(abData)
Debug.Print Hex(abData(i));
Next
Debug.Print
CNV_B64StrFromBytes
CNV_B64Filter