CryptoSys PKI Pro Manual

CNV_Base58ToBytes

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

VBA/VB6 Syntax

Public Declare Function CNV_Base58ToBytes Lib "diCrPKI.dll" (ByRef lpOutput As Byte, ByVal nOutBytes As Long, ByVal strInput As String) As Long

nRet = CNV_Base58ToBytes(lpOutput(0), nOutBytes, strInput)

C/C++ Syntax

long __stdcall CNV_Base58ToBytes(unsigned char *lpOutput, long nOutBytes, const char *szInput);

Parameters

lpOutput
[out] array suitably dimensioned to receive decoded output.
nOutBytes
[in] specifying the maximum number of bytes to be received.
szInput
[in] base58 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 cnvBase58ToBytes (szInput As String) As Byte()

.NET Equivalent

Cnv.FromBase58 Method

C++ (STL) Equivalent

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

Python Equivalent

static Cnv.frombase58(s)

Remarks

This uses the "Bitcoin" scheme of base58 encoding where the leading character '1' is reserved for representing an entire leading zero byte [BTC-B58]. Pass a zero value for nOutBytes to find the required number of bytes in the output array.

Example (VBA core function)

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

' Decode base58 string to byte array
strBase58 = "16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM"
Debug.Print "INPUT: " & strBase58
nBytes = CNV_Base58ToBytes(0, 0, strBase58)
If nBytes < 0 Then Exit Sub ' ERROR
ReDim abData(nBytes - 1)
nBytes = CNV_Base58ToBytes(abData(0), nBytes, strBase58)
' Display byte array in hex
Debug.Print "OUTPUT=" & cnvHexStrFromBytes(abData)

' Again (plug!)
strBase58 = "DiManagement"
Debug.Print "INPUT: " & strBase58
nBytes = CNV_Base58ToBytes(0, 0, strBase58)
If nBytes < 0 Then Exit Sub ' ERROR
ReDim abData(nBytes - 1)
nBytes = CNV_Base58ToBytes(abData(0), nBytes, strBase58)
' Display byte array in hex
Debug.Print "OUTPUT=" & cnvHexStrFromBytes(abData)
INPUT: 16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM
OUTPUT=00010966776006953D5567439E5E39F86A0D273BEED61967F6
INPUT: DiManagement
OUTPUT=11385B5358CD2B71E9

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_Base58FromBytes

[Contents] [Index]

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

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