CryptoSys PKI Toolkit Manual

CNV_B64StrFromBytes

CNV_B64StrFromBytes encodes an array of bytes into a base64-encoded string.

VB6/VBA Syntax

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)

Parameters

strB64
[out] String to receive encoded data.
nB64StrLen
[in] Long specifying the maximum number of characters to be received.
abData
[in] Byte array of binary data to be encoded.
nDataLen
[in] Long number of bytes to be encoded.

C/C++ Syntax

long _stdcall CNV_B64StrFromBytes(char *szOutput, long nOutChars, const unsigned char *input, long nbytes);

Returns (VB6/C)

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

.NET Equivalent

Use the in-built method System.Convert.ToBase64String.

Remarks

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.

Example

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

See Also

CNV_BytesFromB64Str CNV_B64Filter

[Contents] [Index]

[HOME]   [NEXT: CNV_BytesFromB64Str...]

Copyright © 2004-9 D.I. Management Services Pty Ltd. All rights reserved.