CryptoSys PKI Pro Manual

CNV_Base58FromBytes

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

VBA/VB6 Syntax

Public Declare Function CNV_Base58FromBytes Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByRef lpInput As Byte, ByVal nInputLen As Long) As Long

nRet = CNV_Base58FromBytes(strOutput, nOutChars, lpInput(0), nInputLen)

C/C++ Syntax

long __stdcall CNV_Base58FromBytes(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 cnvBase58FromBytes (lpInput() As Byte) As String

.NET Equivalent

Cnv.ToBase58 Method

C++ (STL) Equivalent

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

Python Equivalent

static Cnv.tobase58(data)

Remarks

For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.

This uses the "Bitcoin" scheme of base58 encoding where the leading character '1' is reserved for representing an entire leading zero byte [BTC-B58].

Example (VBA core function)

Dim strBase58 As String
Dim abData() As Byte
Dim nBytes As Long
Dim nChars As Long

' Create a byte array for testing
abData = cnvBytesFromHexStr("00010966776006953D5567439E5E39F86A0D273BEED61967F6")
nBytes = UBound(abData) + 1
Debug.Print "INPUT: " & cnvHexStrFromBytes(abData)

' Encode bytes as base58 string
' Find length of output string
nChars = CNV_Base58FromBytes("", 0, abData(0), nBytes)
If nChars < 0 Then Exit Sub ' ERROR
' Dimension string to receive output
strBase58 = String(nChars, " ")
' Create output string
nChars = CNV_Base58FromBytes(strBase58, nChars, abData(0), nBytes)

Debug.Print "OUTPUT: " & strBase58
INPUT: 00010966776006953D5567439E5E39F86A0D273BEED61967F6
OUTPUT: 16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM

Example (VBA wrapper function)

Dim lpData() As Byte
Dim strBase58 As String

lpData = cnvBytesFromHexStr("00010966776006953D5567439E5E39F86A0D273BEED61967F6")
strBase58 = cnvBase58FromBytes(lpData)
Debug.Print strBase58
' Decode base58 string to byte array
lpData = cnvBase58ToBytes(strBase58)
Debug.Print cnvHexStrFromBytes(lpData)
strBase58 = "DiManagement"
Debug.Print "INPUT: " & strBase58
lpData = cnvBase58ToBytes(strBase58)
Debug.Print cnvHexStrFromBytes(lpData)
   

See Also

CNV_Base58ToBytes

[Contents] [Index]

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

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