Encodes an array of bytes into a base64-encoded string.
Public Declare Function CNV_B64StrFromBytes Lib "diCryptoSys.dll"
(ByVal strOutput As String, ByVal nMaxChars As Long,
ByRef lpData As Byte, ByVal nDataLen As Long) As Long
nRet = CNV_B64StrFromBytes(strOutput, nMaxChars, abData(0), nDataLen)
long __stdcall CNV_B64StrFromBytes(char *szOutput, long nMaxChars, const unsigned char *lpInput, long nBytes);
If successful, the return value is the number of characters in the encoded string; otherwise it returns a negative error code.
Public Function cnvB64StrFromBytes
(lpData() As Byte) As String
Cnv.ToBase64 Method (Byte[])
or use the in-built method System.Convert.ToBase64String
(less forgiving).
static std::string crsysapi::Cnv::ToBase64 (const bvec_t &bv)
static std::string crsysapi::Cnv::ToBase64 (const std::string &s)
static Cnv.tobase64(data)
For the "raw" function, specify a zero nOutChars or a null string for szOutput to find the required length of the output string. C/C++ users must add one to this value when allocating memory.
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 strBase64 = "" ' Convert back to a base64 string strBase64 = cnvB64StrFromBytes(abData) Debug.Print strBase64
Producing the output:
FEDCBA9876543210 /ty6mHZUMhA=
CNV_BytesFromB64Str
CNV_B64Filter