Encodes an array of bytes into a base64-encoded string.
Public Declare Function CNV_B64StrFromBytes Lib "diCrPKI.dll"
(ByVal strB64 As String, ByVal nB64StrLen As Long,
ByRef abData As Byte, ByVal nDataLen As Long) As Long
nRet = CNV_B64StrFromBytes(strB64, nB64StrLen, abData(0), nDataLen)
String to receive encoded data.Long specifying the maximum number of characters to be received.Byte array of binary data to be encoded.Long number of bytes to be encoded.
long _stdcall CNV_B64StrFromBytes(char *szOutput, long nOutChars, const unsigned char *input, long nbytes);
Long: If successful, the return value is the number of characters in the encoded string;
otherwise it returns a negative error code.
Use System.Convert.ToBase64String or (safer)
Cnv.ToBase64 Method (Byte[])
The input array may contain bytes of any value.
If vbNullString or an empty string ("") is specified for strB64 or zero for nB64StrLen,
the function will return
the maximum possible size of the encoded string. The final result may be smaller.
C/C++ programmers should add one to the returned length value when allocating memory.
This wrapper function returns a base64-encoded string directly:
Public Function cnvB64StrFromBytes(abData() As Byte) As String
On Error GoTo CatchEmptyData
Dim strB64 As String
Dim nB64Len As Long
Dim nDataLen As Long
nDataLen = UBound(abData) - LBound(abData) + 1
nB64Len = CNV_B64StrFromBytes("", 0, abData(0), nDataLen)
If nB64Len <= 0 Then
Exit Function
End If
strB64 = String$(nB64Len, " ")
nB64Len = CNV_B64StrFromBytes(strB64, nB64Len, abData(0), nDataLen)
cnvB64StrFromBytes = Left$(strB64, nB64Len)
CatchEmptyData:
End Function
CNV_BytesFromB64Str CNV_B64Filter