CryptoSys API Library Manual

CNV_B64StrFromBytes

Encodes an array of bytes into a base64-encoded string.

VBA/VB6 Syntax

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)

C/C++ Syntax

long __stdcall CNV_B64StrFromBytes(char *szOutput, long nMaxChars, const unsigned char *lpInput, long nBytes);

Parameters

szOutput
[out] to receive encoded data.
nMaxChars
[in] specifying the maximum number of characters to be received.
lpInput
[in] array of binary data to be encoded.
nBytes
[in] number of bytes to be encoded.

Returns (VBA/C)

If successful, the return value is the number of characters in the encoded string; otherwise it returns a negative error code.

VBA Wrapper Syntax

Public Function cnvB64StrFromBytes(lpData() As Byte) As String

.NET Equivalent

Cnv.ToBase64 Method (Byte[])

or use the in-built method System.Convert.ToBase64String (less forgiving).

C++ (STL) Equivalent

static std::string crsysapi::Cnv::ToBase64 (const bvec_t &bv)
static std::string crsysapi::Cnv::ToBase64 (const std::string &s)

Python Equivalent

static Cnv.tobase64(data)

Remarks

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.

Example

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=

See Also

CNV_BytesFromB64Str CNV_B64Filter

[Contents] [Index]

[PREV: CNV_B64Filter...]   [Contents]   [Index]   
   [NEXT: CNV_BytesFromB64Str...]

Copyright © 2001-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-01-07T07:42:00Z.