CryptoSys API Library Manual

CNV_BytesFromB64Str

Decodes a base64-encoded string into an array of Bytes.

VBA/VB6 Syntax

Public Declare Function CNV_BytesFromB64Str Lib "diCryptoSys.dll" (ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strInput As String) As Long

nLen = CNV_BytesFromB64Str(abData(0), nDataLen, strInput)

C/C++ Syntax

long __stdcall CNV_BytesFromB64Str(unsigned char *lpOutput, long nOutputLen, const char *szInput);

Parameters

lpOutput
[out] array suitably dimensioned to receive output.
nOutputLen
[in] specifying the length of the byte array.
szInput
[in] of base64 data to be decoded.

Returns (VBA/C)

If successful, the return value is the number of bytes in the decoded array; otherwise it returns a negative error code.

VBA Wrapper Syntax

Public Function cnvBytesFromB64Str(szB64 As String) As Byte()

.NET Equivalent

Cnv.FromBase64 Method

Or use the in-built method System.Convert.FromBase64String (less forgiving).

C++ (STL) Equivalent

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

Python Equivalent

static Cnv.frombase64(s)

Remarks

This uses the base64 encoding scheme from [RFC4648]. Pass a zero value for nOutBytes to find the required maximum possible number of bytes in the output array. The final array may be shorter.

@warning [Changed in v5.2] This function now returns an error if it finds an illegal character in the input string (previously any non-base64 character was just ignored). Whitespace characters (space, TAB, LF, CR, VT, FF) are still allowed and ignored but any other non-base64 characters will cause an error.

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

See Also

CNV_B64StrFromBytes CNV_B64Filter

[Contents] [Index]

[PREV: CNV_B64StrFromBytes...]   [Contents]   [Index]   
   [NEXT: CNV_BytesFromHexStr...]

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