Encodes an array of bytes into a base64-encoded string.
Public Declare Function CNV_B64StrFromBytes Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByRef lpInput As Byte, ByVal nInputLen As Long) As Long
nRet = CNV_B64StrFromBytes(strOutput, nOutChars, lpInput(0), nInputLen)
long __stdcall CNV_B64StrFromBytes(char *szOutput, long nOutChars, const unsigned char *lpInput, long nInputLen);
If successful, the return value is the number of characters in the encoded string; otherwise it returns a negative error code.
cnvB64StrFromBytes (lpData() As Byte) As StringcnvB64StrFromHexStr (szHex As String) As StringcnvB64StrFromString (szData As String) As StringcnvToBase64 (lpData() As Byte) As String
Cnv.ToBase64 Method (Byte[])
Cnv.ToBase64 Method (String)
Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. ANSI C users must add one to this value when allocating memory.
This uses the base64 encoding scheme from [RFC4648]. Pass a zero value of nOutChars to find the required maximum possible number of characters in the output string. The final result may be smaller. C/C++ programmers should add one to the returned length value when allocating memory for szOutput.
The following wrapper function returns a base64-encoded string directly. Note the trap for a runtime error if the input byte array is empty.
Public Function cnvB64StrFromBytes(abData() As Byte) As String ' Returns base64 string encoding of bytes in abData or empty string on error Dim strB64 As String Dim nB64Len As Long Dim nDataLen As Long On Error GoTo CatchEmptyData nDataLen = UBound(abData) - LBound(abData) + 1 nB64Len = CNV_B64StrFromBytes(vbNullString, 0, abData(0), nDataLen) If nB64Len <= 0 Then Exit Function End If strB64 = String$(nB64Len, " ") nB64Len = CNV_B64StrFromBytes(strB64, nB64Len, abData(0), nDataLen) If nB64Len <= 0 Then Exit Function End If cnvB64StrFromBytes = Left$(strB64, nB64Len) CatchEmptyData: End Function
CNV_BytesFromB64Str CNV_B64Filter