Decodes a base58-encoded string into an array of bytes.
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)
long __stdcall CNV_Base58ToBytes(unsigned char *lpOutput, long nOutBytes, const char *szInput);
If successful, the return value is the number of bytes in the decoded array; otherwise it returns a negative error code.
Public Function cnvBase58ToBytes
(szInput As String) As Byte()
static bvec_t dipki::Cnv::FromBase58 (const std::string &s)
static Cnv.frombase58(s)
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.
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
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)