Encodes an array of bytes into a base58-encoded string.
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)
long __stdcall CNV_Base58FromBytes(char *szOutput, long nOutChars, const unsigned char *lpInput, long nInputLen);
If successful, the return value is the number of characters in the encoded string; otherwise it returns a negative error code.
Public Function cnvBase58FromBytes
(lpInput() As Byte) As String
static std::string dipki::Cnv::ToBase58 (const bvec_t &bv)
static Cnv.tobase58(data)
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].
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
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)