Class Base58
- All Implemented Interfaces:
BinaryDecoder, BinaryEncoder, Decoder, Encoder
Base58 is a binary-to-text encoding scheme that uses a 58-character alphabet to encode data. It avoids characters that can be confused (0/O, I/l, +/) and is commonly used in Bitcoin and other blockchain systems.
Encoding and decoding produce results when EOF is signaled.
Decoding rejects input longer than a configurable maximum (DEFAULT_MAX_DECODE_LENGTH encoded bytes by default, see
Base58.Builder.setMaxDecodeLength(int)). Encoding rejects binary input longer than DEFAULT_MAX_ENCODE_LENGTH bytes by default; configure it with
Base58.Builder.setMaxEncodeLength(int). These limits apply to the total input across all chunks in an operation. Memory usage is proportional to the
accumulated input and conversion output. Encoded output can exceed the decode limit; configure both limits appropriately for larger trusted values.
This class is thread-safe for read operations but the Context object used during encoding/decoding should not be shared between threads.
The Base58 alphabet is:
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
This excludes: 0, I, O, and l.
- Since:
- 1.22.0
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class BaseNCodec
BaseNCodec.AbstractBuilder<T,B> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default maximum number of encoded bytes accepted by a single decode operation: 8192.static final intThe default maximum number of binary bytes accepted by a single encode operation: 8192.Fields inherited from class BaseNCodec
DECODING_POLICY_DEFAULT, lineLength, MASK_8BITS, MIME_CHUNK_SIZE, pad, PAD, PAD_DEFAULT, PEM_CHUNK_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionBase58()Constructs a Base58 codec used for encoding and decoding.Base58(Base58.Builder builder) Constructs a Base58 codec used for encoding and decoding with custom configuration. -
Method Summary
Modifier and TypeMethodDescriptionstatic Base58.Builderbuilder()Creates a new Builder.longgetEncodedLength(byte[] array) Gets the number of Base58 characters needed to encode the supplied array.protected booleanisInAlphabet(byte value) Tests whether theoctetis in the Base58 alphabet.Methods inherited from class BaseNCodec
containsAlphabetOrPad, decode, decode, decode, encode, encode, encode, encodeAsString, encodeToString, ensureBufferSize, getChunkSeparator, getCodecPolicy, getDefaultBufferSize, isInAlphabet, isInAlphabet, isStrictDecoding, isWhiteSpace
-
Field Details
-
DEFAULT_MAX_DECODE_LENGTH
The default maximum number of encoded bytes accepted by a single decode operation: 8192.Use
Base58.Builder.setMaxDecodeLength(int)to raise (or effectively disable) the limit for trusted input.- Since:
- 1.23.0
- See Also:
-
DEFAULT_MAX_ENCODE_LENGTH
The default maximum number of binary bytes accepted by a single encode operation: 8192.Use
Base58.Builder.setMaxEncodeLength(int)to raise (or effectively disable) the limit for trusted input.- Since:
- 1.23.0
- See Also:
-
-
Constructor Details
-
Base58
public Base58()Constructs a Base58 codec used for encoding and decoding. -
Base58
Constructs a Base58 codec used for encoding and decoding with custom configuration.- Parameters:
builder- The builder with custom configuration.
-
-
Method Details
-
builder
Creates a new Builder.To configure a new instance, use a
Base58.Builder. For example:Base58 base58 = Base58.builder() .setMaxEncodeLength(4096) .get()
- Returns:
- A new Builder.
-
getEncodedLength
Gets the number of Base58 characters needed to encode the supplied array.The length depends on the input bytes, including leading zeros. This method observes the configured maximum encode length.
- Overrides:
getEncodedLengthin classBaseNCodec- Parameters:
array- The binary input to encode.- Returns:
- The number of Base58 characters that encoding the array produces.
- Throws:
IllegalArgumentException- Thrown if the input exceeds the configured maximum encode length.- Since:
- 1.23.0
-
isInAlphabet
Tests whether theoctetis in the Base58 alphabet.- Specified by:
isInAlphabetin classBaseNCodec- Parameters:
value- The value to test.- Returns:
trueif the value is defined in the Base58 alphabetfalseotherwise.
-