CryptoSys PKI Pro Manual

CNV_B64StrFromBytes

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

VBA/VB6 Syntax

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)

C/C++ Syntax

long __stdcall CNV_B64StrFromBytes(char *szOutput, long nOutChars, const unsigned char *lpInput, long nInputLen);

Parameters

szOutput
[out] to receive encoded data.
nOutChars
[in] specifying the maximum number of characters to be received.
lpInput
[in] array of binary data to be encoded.
nInputLen
[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
Public Function cnvB64StrFromHexStr (szHex As String) As String
Public Function cnvB64StrFromString (szData As String) As String
Public Function cnvToBase64 (lpData() As Byte) As String

.NET Equivalent

Cnv.ToBase64 Method (Byte[])
Cnv.ToBase64 Method (String)

C++ (STL) Equivalent

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

Python Equivalent

static Cnv.tobase64(data)

Remarks

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.

Example (VBA core function)

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

See Also

CNV_BytesFromB64Str CNV_B64Filter

[Contents] [Index]

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

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.