Skip to content

Base58

Base58 is an encoding method that converts binary data to ASCII characters, using 58 characters (1-9, A-Z, a-z, excluding easily confused characters 0, O, I, l) to represent data. dongle supports standard Base58 encoding, following Bitcoin-style specifications.

The default alphabet is 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz, You can customize the alphabet by setting base58.StdAlphabet

Encoding Data

Input Data

go
// Input string
encoder := dongle.Encode.FromString("hello world").ByBase58()

// Input byte slice
encoder := dongle.Encode.FromBytes([]byte("hello world")).ByBase58()

// Input file stream
file, _ := os.Open("test.txt")
encoder := dongle.Encode.FromFile(file).ByBase58()

// Check encoding error
if encoder.Error != nil {
	fmt.Printf("Encoding error: %v\n", encoder.Error)
	return
}

Output Data

go
// Output string
encoder.ToString() // StV1DL6CwTryKyV
// Output byte slice
encoder.ToBytes()  // []byte("StV1DL6CwTryKyV")

Decoding Data

Input Data

go
// Input string
decoder := dongle.Decode.FromString("StV1DL6CwTryKyV").ByBase58()

// Input byte slice
decoder := dongle.Decode.FromBytes([]byte("StV1DL6CwTryKyV")).ByBase58()

// Input file stream
file, _ := os.Open("test.txt")
decoder := dongle.Decode.FromFile(file).ByBase58()

// Check decoding error
if decoder.Error != nil {
	fmt.Printf("Decoding error: %v\n", decoder.Error)
	return
}

Output Data

go
// Output string
decoder.ToString() // hello world
// Output byte slice
decoder.ToBytes()  // []byte("hello world")

Released under the MIT License, unauthorized reproduction is prohibited in any form