This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git


The following commit(s) were added to refs/heads/master by this push:
     new 15ce4291 [CODEC-326] Add Base58 support
15ce4291 is described below

commit 15ce42914d8c275a2d9dd82082a19d759d517e6f
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Feb 7 08:56:09 2026 -0500

    [CODEC-326] Add Base58 support
    
    - Javadoc
    - Sort members
    - Reduce vertical whitespace
    - Remove deprecated and unreleased constructors
---
 src/changes/changes.xml                            |   3 +-
 .../org/apache/commons/codec/binary/Base58.java    | 292 ++++++++++-----------
 .../commons/codec/binary/Base58InputStream.java    |  15 +-
 .../commons/codec/binary/Base58OutputStream.java   |  18 +-
 .../codec/binary/Base58InputStreamTest.java        |  97 +++----
 .../codec/binary/Base58OutputStreamTest.java       |  31 +--
 .../apache/commons/codec/binary/Base58Test.java    | 119 ++++-----
 .../apache/commons/codec/binary/Base64Test.java    |  12 +-
 8 files changed, 243 insertions(+), 344 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f760dccc..8cd1cbe1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -43,9 +43,10 @@ The <action> type attribute can be add,update,fix,remove.
     <author>Apache Commons Developers</author>
   </properties>
   <body>
-    <release version="1.21.1" date="YYYY-MM-DD" description="This is a feature 
and maintenance release. Java 8 or later is required.">
+    <release version="1.22.0" date="YYYY-MM-DD" description="This is a feature 
and maintenance release. Java 8 or later is required.">
       <!-- FIX -->
       <!-- ADD -->
+      <action type="add" dev="ggregory" due-to="Inkeet, Gary Gregory, Wolff 
Bock von Wuelfingen" issue="CODEC-326">Add Base58 support.</action>
       <!-- UPDATE -->
     </release>
     <release version="1.21.0" date="2026-01-23" description="This is a feature 
and maintenance release. Java 8 or later is required.">
diff --git a/src/main/java/org/apache/commons/codec/binary/Base58.java 
b/src/main/java/org/apache/commons/codec/binary/Base58.java
index f94938b2..ec27470f 100644
--- a/src/main/java/org/apache/commons/codec/binary/Base58.java
+++ b/src/main/java/org/apache/commons/codec/binary/Base58.java
@@ -25,32 +25,72 @@ import java.util.WeakHashMap;
 /**
  * Provides Base58 encoding and decoding as commonly used in cryptocurrency 
and blockchain applications.
  * <p>
- * 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.
+ * 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.
  * </p>
  * <p>
- * This implementation accumulates data internally until EOF is signaled, at 
which point the entire input is
- * converted using BigInteger arithmetic. This is necessary because Base58 
encoding/decoding requires access
- * to the complete data to properly handle leading zeros.
+ * This implementation accumulates data internally until EOF is signaled, at 
which point the entire input is converted using BigInteger arithmetic. This is
+ * necessary because Base58 encoding/decoding requires access to the complete 
data to properly handle leading zeros.
  * </p>
  * <p>
- * This class is thread-safe for read operations but the Context object used 
during encoding/decoding should
- * not be shared between threads.
+ * This class is thread-safe for read operations but the Context object used 
during encoding/decoding should not be shared between threads.
  * </p>
  * <p>
- * The Base58 alphabet is: 
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
- * (excludes: 0, I, O, l)
+ * The Base58 alphabet is:
+ * </p>
+ *
+ * <pre>
+ * 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
+ * </pre>
+ * <p>
+ * This excludes: {@code 0}, {@code I}, {@code O}, and {@code l}.
  * </p>
  *
  * @see Base58InputStream
  * @see Base58OutputStream
+ * @see <a 
href="https://datatracker.ietf.org/doc/html/draft-msporny-base58-03";>The Base58 
Encoding Scheme draft-msporny-base58-03</a>
  * @since 1.22.0
  */
 public class Base58 extends BaseNCodec {
 
+    /**
+     * Builds {@link Base58} instances with custom configuration.
+     */
+    public static class Builder extends AbstractBuilder<Base58, 
Base58.Builder> {
+
+        /**
+         * Constructs a new Base58 builder.
+         */
+        public Builder() {
+            super(ENCODE_TABLE);
+            setDecodeTable(DECODE_TABLE);
+        }
+
+        /**
+         * Builds a new Base58 instance with the configured settings.
+         *
+         * @return a new Base58 codec
+         */
+        @Override
+        public Base58 get() {
+            return new Base58(this);
+        }
+
+        /**
+         * Creates a new Base58 codec instance.
+         *
+         * @return a new Base58 codec.
+         */
+        @Override
+        public Base58.Builder setEncodeTable(final byte... encodeTable) {
+            super.setDecodeTableRaw(DECODE_TABLE);
+            return super.setEncodeTable(encodeTable);
+        }
+    }
+
     /**
      * Base58 alphabet: 
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
-     * (excludes: 0, I, O, l)
+     * (excludes: 0, I, O, l).
      */
     private static final byte[] ENCODE_TABLE = {
             '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 
'E', 'F', 'G', 'H',
@@ -75,6 +115,7 @@ public class Base58 extends BaseNCodec {
             -1, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, -1, 44, 45, 46, // 
60-6f 'a'-'k', 'm'-'o' (skip 'l')
             47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,                     // 
70-7a 'p'-'z'
     };
+
     private final transient Map<Context, byte[]> accumulated = new 
WeakHashMap<>();
 
     /**
@@ -87,30 +128,93 @@ public class Base58 extends BaseNCodec {
     /**
      * Constructs a Base58 codec used for encoding and decoding with custom 
configuration.
      *
-     * @param builder the builder with custom configuration
+     * @param builder the builder with custom configuration.
      */
     public Base58(final Builder builder) {
         super(builder);
     }
 
+    /**
+     * Converts Base58 encoded data to binary.
+     * <p>
+     * Uses BigInteger arithmetic to convert the Base58 string to binary data. 
Leading '1' characters in the Base58 encoding represent leading zero bytes in 
the
+     * binary data.
+     * </p>
+     *
+     * @param base58Data the Base58 encoded data.
+     * @param context    the context for this decoding operation.
+     * @throws IllegalArgumentException if the Base58 data contains invalid 
characters.
+     */
+    private void convertFromBase58(final byte[] base58Data, final Context 
context) {
+        BigInteger value = BigInteger.ZERO;
+        int leadingOnes = 0;
+        for (final byte b : base58Data) {
+            if (b != '1') {
+                break;
+            }
+            leadingOnes++;
+        }
+        final BigInteger base = BigInteger.valueOf(58);
+        BigInteger power = BigInteger.ONE;
+        for (int i = base58Data.length - 1; i >= leadingOnes; i--) {
+            final byte b = base58Data[i];
+            final int digit = b < DECODE_TABLE.length ? DECODE_TABLE[b] : -1;
+            if (digit < 0) {
+                throw new IllegalArgumentException("Invalid character in 
Base58 string: " + (char) b);
+            }
+            value = value.add(BigInteger.valueOf(digit).multiply(power));
+            power = power.multiply(base);
+        }
+        byte[] decoded = value.toByteArray();
+        if (decoded.length > 1 && decoded[0] == 0) {
+            final byte[] tmp = new byte[decoded.length - 1];
+            System.arraycopy(decoded, 1, tmp, 0, tmp.length);
+            decoded = tmp;
+        }
+        final byte[] result = new byte[leadingOnes + decoded.length];
+        System.arraycopy(decoded, 0, result, leadingOnes, decoded.length);
+        final byte[] buffer = ensureBufferSize(result.length, context);
+        System.arraycopy(result, 0, buffer, context.pos, result.length);
+        context.pos += result.length;
+    }
+
+    /**
+     * Converts accumulated binary data to Base58 encoding.
+     * <p>
+     * Uses BigInteger arithmetic to convert the binary data to Base58. 
Leading zeros in the binary data are represented as '1' characters in the Base58
+     * encoding.
+     * </p>
+     *
+     * @param accumulate the binary data to encode
+     * @param context    the context for this encoding operation
+     * @return the buffer containing the encoded data
+     */
+    private byte[] convertToBase58(final byte[] accumulate, final Context 
context) {
+        final StringBuilder base58 = getStringBuilder(accumulate);
+        final String encoded = base58.reverse().toString();
+        final byte[] encodedBytes = encoded.getBytes(StandardCharsets.UTF_8);
+        final byte[] buffer = ensureBufferSize(encodedBytes.length, context);
+        System.arraycopy(encodedBytes, 0, buffer, context.pos, 
encodedBytes.length);
+        context.pos += encodedBytes.length;
+        return buffer;
+    }
+
     /**
      * Decodes the given Base58 encoded data.
      * <p>
-     * This implementation accumulates data internally. When length &lt; 0 
(EOF), the accumulated
-     * data is converted from Base58 to binary.
+     * This implementation accumulates data internally. When length &lt; 0 
(EOF), the accumulated data is converted from Base58 to binary.
      * </p>
      *
-     * @param array   the byte array containing Base58 encoded data
-     * @param offset  the offset in the array to start from
-     * @param length  the number of bytes to decode, or negative to signal EOF
-     * @param context the context for this decoding operation
+     * @param array   the byte array containing Base58 encoded data.
+     * @param offset  the offset in the array to start from.
+     * @param length  the number of bytes to decode, or negative to signal EOF.
+     * @param context the context for this decoding operation.
      */
     @Override
-    void decode(byte[] array, int offset, int length, Context context) {
+    void decode(final byte[] array, final int offset, final int length, final 
Context context) {
         if (context.eof) {
             return;
         }
-
         if (length < 0) {
             context.eof = true;
             final byte[] accumulate = accumulated.getOrDefault(context, new 
byte[0]);
@@ -120,7 +224,6 @@ public class Base58 extends BaseNCodec {
             accumulated.remove(context);
             return;
         }
-
         final byte[] accumulate = accumulated.getOrDefault(context, new 
byte[0]);
         final byte[] newAccumulated = new byte[accumulate.length + length];
         if (accumulate.length > 0) {
@@ -133,21 +236,19 @@ public class Base58 extends BaseNCodec {
     /**
      * Encodes the given binary data as Base58.
      * <p>
-     * This implementation accumulates data internally. When length &lt; 0 
(EOF), the accumulated
-     * data is converted to Base58.
+     * This implementation accumulates data internally. When length &lt; 0 
(EOF), the accumulated data is converted to Base58.
      * </p>
      *
-     * @param array   the byte array containing binary data to encode
-     * @param offset  the offset in the array to start from
-     * @param length  the number of bytes to encode, or negative to signal EOF
-     * @param context the context for this encoding operation
+     * @param array   the byte array containing binary data to encode.
+     * @param offset  the offset in the array to start from.
+     * @param length  the number of bytes to encode, or negative to signal EOF.
+     * @param context the context for this encoding operation.
      */
     @Override
-    void encode(byte[] array, int offset, int length, Context context) {
+    void encode(final byte[] array, final int offset, final int length, final 
Context context) {
         if (context.eof) {
             return;
         }
-
         if (length < 0) {
             context.eof = true;
             final byte[] accumulate = accumulated.getOrDefault(context, new 
byte[0]);
@@ -155,7 +256,6 @@ public class Base58 extends BaseNCodec {
             accumulated.remove(context);
             return;
         }
-
         final byte[] accumulate = accumulated.getOrDefault(context, new 
byte[0]);
         final byte[] newAccumulated = new byte[accumulate.length + length];
         if (accumulate.length > 0) {
@@ -165,117 +265,37 @@ public class Base58 extends BaseNCodec {
         accumulated.put(context, newAccumulated);
     }
 
-    /**
-     * Converts accumulated binary data to Base58 encoding.
-     * <p>
-     * Uses BigInteger arithmetic to convert the binary data to Base58. 
Leading zeros in the
-     * binary data are represented as '1' characters in the Base58 encoding.
-     * </p>
-     *
-     * @param accumulate the binary data to encode
-     * @param context    the context for this encoding operation
-     * @return the buffer containing the encoded data
-     */
-    private byte[] convertToBase58(byte[] accumulate, Context context) {
-        final StringBuilder base58 = getStringBuilder(accumulate);
-        final String encoded = base58.reverse().toString();
-
-        final byte[] encodedBytes = encoded.getBytes(StandardCharsets.UTF_8);
-        final byte[] buffer = ensureBufferSize(encodedBytes.length, context);
-        System.arraycopy(encodedBytes, 0, buffer, context.pos, 
encodedBytes.length);
-        context.pos += encodedBytes.length;
-        return buffer;
-    }
-
     /**
      * Builds the Base58 string representation of the given binary data.
      * <p>
-     * Converts binary data to a BigInteger and divides by 58 repeatedly to 
get the Base58 digits.
-     * Handles leading zeros by counting them and appending '1' for each 
leading zero byte.
+     * Converts binary data to a BigInteger and divides by 58 repeatedly to 
get the Base58 digits. Handles leading zeros by counting them and appending '1' 
for
+     * each leading zero byte.
      * </p>
      *
-     * @param accumulate the binary data to convert
-     * @return a StringBuilder with the Base58 representation (not yet 
reversed)
+     * @param accumulate the binary data to convert.
+     * @return a StringBuilder with the Base58 representation (not yet 
reversed).
      */
-    private StringBuilder getStringBuilder(byte[] accumulate) {
+    private StringBuilder getStringBuilder(final byte[] accumulate) {
         BigInteger value = new BigInteger(1, accumulate);
         int leadingZeros = 0;
-
-        for (byte b : accumulate) {
-            if (b == 0) {
-                leadingZeros++;
-            } else {
+        for (final byte b : accumulate) {
+            if (b != 0) {
                 break;
             }
+            leadingZeros++;
         }
-
         final StringBuilder base58 = new StringBuilder();
         while (value.signum() > 0) {
             final BigInteger[] divRem = 
value.divideAndRemainder(BigInteger.valueOf(58));
             base58.append((char) ENCODE_TABLE[divRem[1].intValue()]);
             value = divRem[0];
         }
-
         for (int i = 0; i < leadingZeros; i++) {
             base58.append('1');
         }
         return base58;
     }
 
-    /**
-     * Converts Base58 encoded data to binary.
-     * <p>
-     * Uses BigInteger arithmetic to convert the Base58 string to binary data. 
Leading '1' characters
-     * in the Base58 encoding represent leading zero bytes in the binary data.
-     * </p>
-     *
-     * @param base58Data the Base58 encoded data
-     * @param context    the context for this decoding operation
-     * @throws IllegalArgumentException if the Base58 data contains invalid 
characters
-     */
-    private void convertFromBase58(byte[] base58Data, Context context) {
-        BigInteger value = BigInteger.ZERO;
-        int leadingOnes = 0;
-
-        for (byte b : base58Data) {
-            if (b == '1') {
-                leadingOnes++;
-            } else {
-                break;
-            }
-        }
-
-        final BigInteger base = BigInteger.valueOf(58);
-        BigInteger power = BigInteger.ONE;
-
-        for (int i = base58Data.length - 1; i >= leadingOnes; i--) {
-            final byte b = base58Data[i];
-            final int digit = b < DECODE_TABLE.length ? DECODE_TABLE[b] : -1;
-
-            if (digit < 0) {
-                throw new IllegalArgumentException("Invalid character in 
Base58 string: " + (char) b);
-            }
-
-            value = value.add(BigInteger.valueOf(digit).multiply(power));
-            power = power.multiply(base);
-        }
-
-        byte[] decoded = value.toByteArray();
-
-        if (decoded.length > 1 && decoded[0] == 0) {
-            final byte[] tmp = new byte[decoded.length - 1];
-            System.arraycopy(decoded, 1, tmp, 0, tmp.length);
-            decoded = tmp;
-        }
-
-        final byte[] result = new byte[leadingOnes + decoded.length];
-        System.arraycopy(decoded, 0, result, leadingOnes, decoded.length);
-
-        final byte[] buffer = ensureBufferSize(result.length, context);
-        System.arraycopy(result, 0, buffer, context.pos, result.length);
-        context.pos += result.length;
-    }
-
     /**
      * Returns whether or not the {@code octet} is in the Base58 alphabet.
      *
@@ -283,43 +303,7 @@ public class Base58 extends BaseNCodec {
      * @return {@code true} if the value is defined in the Base58 alphabet 
{@code false} otherwise.
      */
     @Override
-    protected boolean isInAlphabet(byte value) {
+    protected boolean isInAlphabet(final byte value) {
         return value >= 0 && value < DECODE_TABLE.length && 
DECODE_TABLE[value] != -1;
     }
-
-    /**
-     * Builds {@link Base58} instances with custom configuration.
-     */
-    public static class Builder extends AbstractBuilder<Base58, 
Base58.Builder> {
-
-        /**
-         * Constructs a new Base58 builder.
-         */
-        public Builder() {
-            super(ENCODE_TABLE);
-            setDecodeTable(DECODE_TABLE);
-        }
-
-        /**
-         * Builds a new Base58 instance with the configured settings.
-
-         * @return a new Base58 codec
-         */
-        @Override
-        public Base58 get() {
-            return new Base58(this);
-        }
-
-        /**
-         * Creates a new Base58 codec instance.
-         *
-         * @return a new Base58 codec
-         */
-        @Override
-        public Base58.Builder setEncodeTable(final byte... encodeTable) {
-            super.setDecodeTableRaw(DECODE_TABLE);
-            return super.setEncodeTable(encodeTable);
-        }
-    }
-
 }
diff --git 
a/src/main/java/org/apache/commons/codec/binary/Base58InputStream.java 
b/src/main/java/org/apache/commons/codec/binary/Base58InputStream.java
index 1c4115a0..394a8bad 100644
--- a/src/main/java/org/apache/commons/codec/binary/Base58InputStream.java
+++ b/src/main/java/org/apache/commons/codec/binary/Base58InputStream.java
@@ -36,7 +36,7 @@ import java.io.InputStream;
  * </p>
  * <ul>
  * <li>Lenient: Any trailing bits are composed into 8-bit bytes where 
possible. The remainder are discarded.</li>
- * <li>Strict: The decoding will raise an {@link IllegalArgumentException} if 
trailing bits are not part of a valid encoding. Any unused bits from the final
+ * <li>Strict: The decoding will throw an {@link IllegalArgumentException} if 
trailing bits are not part of a valid encoding. Any unused bits from the final
  * character must be zero. Impossible counts of entire final characters are 
not allowed.</li>
  * </ul>
  * <p>
@@ -45,6 +45,7 @@ import java.io.InputStream;
  * </p>
  *
  * @see Base58
+ * @see <a 
href="https://datatracker.ietf.org/doc/html/draft-msporny-base58-03";>The Base58 
Encoding Scheme draft-msporny-base58-03</a>
  * @since 1.22.0
  */
 public class Base58InputStream extends BaseNCodecInputStream<Base58, 
Base58InputStream, Base58InputStream.Builder> {
@@ -93,16 +94,4 @@ public class Base58InputStream extends 
BaseNCodecInputStream<Base58, Base58Input
     public Base58InputStream(final InputStream inputStream) {
         super(builder().setInputStream(inputStream));
     }
-
-    /**
-     * Constructs a Base58InputStream such that all data read is either 
Base58-encoded or Base58-decoded from the original provided InputStream.
-     *
-     * @param inputStream InputStream to wrap.
-     * @param encode    true if we should encode all data read from us, false 
if we should decode.
-     * @deprecated Use {@link #builder()} and {@link Builder}.
-     */
-    @Deprecated
-    public Base58InputStream(final InputStream inputStream, final boolean 
encode) {
-        super(builder().setInputStream(inputStream).setEncode(encode));
-    }
 }
diff --git 
a/src/main/java/org/apache/commons/codec/binary/Base58OutputStream.java 
b/src/main/java/org/apache/commons/codec/binary/Base58OutputStream.java
index 06a91e00..593a35d3 100644
--- a/src/main/java/org/apache/commons/codec/binary/Base58OutputStream.java
+++ b/src/main/java/org/apache/commons/codec/binary/Base58OutputStream.java
@@ -40,7 +40,7 @@ import java.io.OutputStream;
  * </p>
  * <ul>
  * <li>Lenient: Any trailing bits are composed into 8-bit bytes where 
possible. The remainder are discarded.</li>
- * <li>Strict: The decoding will raise an {@link IllegalArgumentException} if 
trailing bits are not part of a valid encoding. Any unused bits from the final
+ * <li>Strict: The decoding will throw an {@link IllegalArgumentException} if 
trailing bits are not part of a valid encoding. Any unused bits from the final
  * character must be zero. Impossible counts of entire final characters are 
not allowed.</li>
  * </ul>
  * <p>
@@ -49,6 +49,7 @@ import java.io.OutputStream;
  * </p>
  *
  * @see Base58
+ * @see <a 
href="https://datatracker.ietf.org/doc/html/draft-msporny-base58-03";>The Base58 
Encoding Scheme draft-msporny-base58-03</a>
  * @since 1.22.0
  */
 public class Base58OutputStream extends BaseNCodecOutputStream<Base58, 
Base58OutputStream, Base58OutputStream.Builder> {
@@ -68,7 +69,7 @@ public class Base58OutputStream extends 
BaseNCodecOutputStream<Base58, Base58Out
         /**
          * Builds a new Base58OutputStream instance with the configured 
settings.
          *
-         * @return a new Base58OutputStream
+         * @return a new Base58OutputStream.
          */
         @Override
         public Base58OutputStream get() {
@@ -78,7 +79,7 @@ public class Base58OutputStream extends 
BaseNCodecOutputStream<Base58, Base58Out
         /**
          * Creates a new Base58 codec instance.
          *
-         * @return a new Base58 codec
+         * @return a new Base58 codec.
          */
         @Override
         protected Base58 newBaseNCodec() {
@@ -108,15 +109,4 @@ public class Base58OutputStream extends 
BaseNCodecOutputStream<Base58, Base58Out
         this(builder().setOutputStream(outputStream));
     }
 
-    /**
-     * Constructs a Base58OutputStream such that all data written is either 
Base58-encoded or Base58-decoded to the original provided OutputStream.
-     *
-     * @param outputStream OutputStream to wrap.
-     * @param encode     true if we should encode all data written to us, 
false if we should decode.
-     * @deprecated Use {@link #builder()} and {@link Builder}.
-     */
-    @Deprecated
-    public Base58OutputStream(final OutputStream outputStream, final boolean 
encode) {
-        super(builder().setOutputStream(outputStream).setEncode(encode));
-    }
 }
diff --git 
a/src/test/java/org/apache/commons/codec/binary/Base58InputStreamTest.java 
b/src/test/java/org/apache/commons/codec/binary/Base58InputStreamTest.java
index aa01c08f..4f730450 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base58InputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base58InputStreamTest.java
@@ -64,8 +64,7 @@ class Base58InputStreamTest {
     /**
      * Tests the Base58InputStream implementation against empty input.
      *
-     * @throws Exception
-     *             for some failure scenarios.
+     * @throws Exception for some failure scenarios.
      */
     @Test
     void testBase58EmptyInputStreamMimeChuckSize() throws Exception {
@@ -75,8 +74,7 @@ class Base58InputStreamTest {
     /**
      * Tests the Base58InputStream implementation against empty input.
      *
-     * @throws Exception
-     *             for some failure scenarios.
+     * @throws Exception for some failure scenarios.
      */
     @Test
     void testBase58EmptyInputStreamPemChuckSize() throws Exception {
@@ -89,7 +87,6 @@ class Base58InputStreamTest {
         byte[] decoded = StringUtils.getBytesUtf8(STRING_FIXTURE);
         byte[] encoded = new Base58().encode(decoded);
         testByChunk(encoded, decoded, BaseNCodec.MIME_CHUNK_SIZE, CRLF);
-
         // test random data of sizes 0 through 150
         final BaseNCodec codec = new Base58();
         for (int i = 0; i <= 150; i++) {
@@ -106,7 +103,6 @@ class Base58InputStreamTest {
         byte[] decoded = StringUtils.getBytesUtf8(STRING_FIXTURE);
         byte[] encoded = new Base58().encode(decoded);
         testByteByByte(encoded, decoded, BaseNCodec.MIME_CHUNK_SIZE, CRLF);
-
         // test random data of sizes 0 through 150
         final BaseNCodec codec = new Base58();
         for (int i = 0; i <= 150; i++) {
@@ -126,22 +122,16 @@ class Base58InputStreamTest {
      * Tests method does three tests on the supplied data: 1. encoded 
---[DECODE]--> decoded 2. decoded ---[ENCODE]--> encoded 3. decoded
      * ---[WRAP-WRAP-WRAP-etc...] --> decoded
      * <p/>
-     * By "[WRAP-WRAP-WRAP-etc...]" we mean situation where the 
Base58InputStream wraps itself in encode and decode mode over and over
-     * again.
+     * By "[WRAP-WRAP-WRAP-etc...]" we mean situation where the 
Base58InputStream wraps itself in encode and decode mode over and over again.
      *
-     * @param encoded
-     *            base58 encoded data
-     * @param decoded
-     *            the data from above, but decoded
-     * @param chunkSize
-     *            chunk size (line-length) of the base58 encoded data.
-     * @param separator
-     *            Line separator in the base58 encoded data.
-     * @throws Exception
-     *             Usually signifies a bug in the Base58 commons-codec 
implementation.
+     * @param encoded   base58 encoded data
+     * @param decoded   the data from above, but decoded
+     * @param chunkSize chunk size (line-length) of the base58 encoded data.
+     * @param separator Line separator in the base58 encoded data.
+     * @throws Exception Usually signifies a bug in the Base58 commons-codec 
implementation.
      */
     private void testByChunk(final byte[] encoded, final byte[] decoded, final 
int chunkSize, final byte[] separator) throws Exception {
-        try (InputStream in = new Base58InputStream(new 
ByteArrayInputStream(decoded), true)) {
+        try (InputStream in = Base58InputStream.builder().setInputStream(new 
ByteArrayInputStream(decoded)).setEncode(true).get()) {
             final byte[] output = BaseNTestData.streamToBytes(in);
             assertEquals(-1, in.read(), "EOF");
             assertEquals(-1, in.read(), "Still EOF");
@@ -149,15 +139,14 @@ class Base58InputStreamTest {
         }
         try (InputStream in = new Base58InputStream(new 
ByteArrayInputStream(encoded))) {
             final byte[] output = BaseNTestData.streamToBytes(in);
-
             assertEquals(-1, in.read(), "EOF");
             assertEquals(-1, in.read(), "Still EOF");
             assertArrayEquals(decoded, output, "Streaming base58 decode");
         }
         InputStream in = new ByteArrayInputStream(decoded);
         for (int i = 0; i < 10; i++) {
-            in = new Base58InputStream(in, true);
-            in = new Base58InputStream(in, false);
+            in = 
Base58InputStream.builder().setInputStream(in).setEncode(true).get();
+            in = 
Base58InputStream.builder().setInputStream(in).setEncode(false).get();
         }
         final byte[] output = BaseNTestData.streamToBytes(in);
         assertEquals(-1, in.read(), "EOF");
@@ -170,45 +159,34 @@ class Base58InputStreamTest {
      * Tests method does three tests on the supplied data: 1. encoded 
---[DECODE]--> decoded 2. decoded ---[ENCODE]--> encoded 3. decoded
      * ---[WRAP-WRAP-WRAP-etc...] --> decoded
      * <p/>
-     * By "[WRAP-WRAP-WRAP-etc...]" we mean situation where the 
Base58InputStream wraps itself in encode and decode mode over and over
-     * again.
+     * By "[WRAP-WRAP-WRAP-etc...]" we mean situation where the 
Base58InputStream wraps itself in encode and decode mode over and over again.
      *
-     * @param encoded
-     *            base58 encoded data
-     * @param decoded
-     *            the data from above, but decoded
-     * @param chunkSize
-     *            chunk size (line-length) of the base58 encoded data.
-     * @param separator
-     *            Line separator in the base58 encoded data.
-     * @throws Exception
-     *             Usually signifies a bug in the Base58 commons-codec 
implementation.
+     * @param encoded   base58 encoded data
+     * @param decoded   the data from above, but decoded
+     * @param chunkSize chunk size (line-length) of the base58 encoded data.
+     * @param separator Line separator in the base58 encoded data.
+     * @throws Exception Usually signifies a bug in the Base58 commons-codec 
implementation.
      */
     private void testByteByByte(final byte[] encoded, final byte[] decoded, 
final int chunkSize, final byte[] separator) throws Exception {
         InputStream in;
-        in = new Base58InputStream(new ByteArrayInputStream(decoded), true);
+        in = Base58InputStream.builder().setInputStream(new 
ByteArrayInputStream(decoded)).setEncode(true).get();
         byte[] output = BaseNTestData.streamToBytes(in);
-
         assertEquals(-1, in.read(), "EOF");
         assertEquals(-1, in.read(), "Still EOF");
         assertArrayEquals(encoded, output, "Streaming base58 encode");
-
         in.close();
         in = new Base58InputStream(new ByteArrayInputStream(encoded));
         output = BaseNTestData.streamToBytes(in);
-
         assertEquals(-1, in.read(), "EOF");
         assertEquals(-1, in.read(), "Still EOF");
         assertArrayEquals(decoded, output, "Streaming base58 decode");
-
         in.close();
         in = new ByteArrayInputStream(decoded);
         for (int i = 0; i < 10; i++) {
-            in = new Base58InputStream(in, true);
-            in = new Base58InputStream(in, false);
+            in = 
Base58InputStream.builder().setInputStream(in).setEncode(true).get();
+            in = 
Base58InputStream.builder().setInputStream(in).setEncode(false).get();
         }
         output = BaseNTestData.streamToBytes(in);
-
         assertEquals(-1, in.read(), "EOF");
         assertEquals(-1, in.read(), "Still EOF");
         assertArrayEquals(decoded, output, "Streaming base58 wrap-wrap-wrap!");
@@ -217,14 +195,13 @@ class Base58InputStreamTest {
     /**
      * Tests markSupported.
      *
-     * @throws Exception
-     *             for some failure scenarios.
+     * @throws Exception for some failure scenarios.
      */
     @Test
     void testMarkSupported() throws Exception {
         final byte[] decoded = StringUtils.getBytesUtf8(STRING_FIXTURE);
         final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
-        try (Base58InputStream in = new Base58InputStream(bin, true)) {
+        try (Base58InputStream in = 
Base58InputStream.builder().setInputStream(bin).setEncode(true).get()) {
             // Always returns false for now.
             assertFalse(in.markSupported(), "Base58InputStream.markSupported() 
is false");
         }
@@ -233,8 +210,7 @@ class Base58InputStreamTest {
     /**
      * Tests read returning 0
      *
-     * @throws Exception
-     *             for some failure scenarios.
+     * @throws Exception for some failure scenarios.
      */
     @Test
     void testRead0() throws Exception {
@@ -242,7 +218,7 @@ class Base58InputStreamTest {
         final byte[] buf = new byte[1024];
         int bytesRead = 0;
         final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
-        try (Base58InputStream in = new Base58InputStream(bin, true)) {
+        try (Base58InputStream in = 
Base58InputStream.builder().setInputStream(bin).setEncode(true).get()) {
             bytesRead = in.read(buf, 0, 0);
             assertEquals(0, bytesRead, "Base58InputStream.read(buf, 0, 0) 
returns 0");
         }
@@ -251,14 +227,13 @@ class Base58InputStreamTest {
     /**
      * Tests read with null.
      *
-     * @throws Exception
-     *             for some failure scenarios.
+     * @throws Exception for some failure scenarios.
      */
     @Test
     void testReadNull() throws Exception {
         final byte[] decoded = StringUtils.getBytesUtf8(STRING_FIXTURE);
         final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
-        try (Base58InputStream in = new Base58InputStream(bin, true)) {
+        try (Base58InputStream in = 
Base58InputStream.builder().setInputStream(bin).setEncode(true).get()) {
             assertThrows(NullPointerException.class, () -> in.read(null, 0, 
0));
         }
     }
@@ -266,15 +241,14 @@ class Base58InputStreamTest {
     /**
      * Tests read throwing IndexOutOfBoundsException
      *
-     * @throws Exception
-     *             for some failure scenarios.
+     * @throws Exception for some failure scenarios.
      */
     @Test
     void testReadOutOfBounds() throws Exception {
         final byte[] decoded = StringUtils.getBytesUtf8(STRING_FIXTURE);
         final byte[] buf = new byte[1024];
         final ByteArrayInputStream bin = new ByteArrayInputStream(decoded);
-        try (Base58InputStream in = new Base58InputStream(bin, true)) {
+        try (Base58InputStream in = 
Base58InputStream.builder().setInputStream(bin).setEncode(true).get()) {
             assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, 
-1, 0), "Base58InputStream.read(buf, -1, 0)");
             assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, 
0, -1), "Base58InputStream.read(buf, 0, -1)");
             assertThrows(IndexOutOfBoundsException.class, () -> in.read(buf, 
buf.length + 1, 0), "Base58InputStream.read(buf, buf.length + 1, 0)");
@@ -285,8 +259,7 @@ class Base58InputStreamTest {
     /**
      * Tests skipping number of characters larger than the internal buffer.
      *
-     * @throws Throwable
-     *             for some failure scenarios.
+     * @throws Throwable for some failure scenarios.
      */
     @Test
     void testSkipBig() throws Throwable {
@@ -303,8 +276,7 @@ class Base58InputStreamTest {
     /**
      * Tests skipping as a noop
      *
-     * @throws Throwable
-     *             for some failure scenarios.
+     * @throws Throwable for some failure scenarios.
      */
     @Test
     void testSkipNone() throws Throwable {
@@ -323,8 +295,7 @@ class Base58InputStreamTest {
     /**
      * Tests skipping past the end of a stream.
      *
-     * @throws Throwable
-     *             for some failure scenarios.
+     * @throws Throwable for some failure scenarios.
      */
     @Test
     void testSkipPastEnd() throws Throwable {
@@ -342,8 +313,7 @@ class Base58InputStreamTest {
     /**
      * Tests skipping to the end of a stream.
      *
-     * @throws Throwable
-     *             for some failure scenarios.
+     * @throws Throwable for some failure scenarios.
      */
     @Test
     void testSkipToEnd() throws Throwable {
@@ -359,8 +329,7 @@ class Base58InputStreamTest {
     /**
      * Tests if negative arguments to skip are handled correctly.
      *
-     * @throws Throwable
-     *             for some failure scenarios.
+     * @throws Throwable for some failure scenarios.
      */
     @Test
     void testSkipWrongArgument() throws Throwable {
diff --git 
a/src/test/java/org/apache/commons/codec/binary/Base58OutputStreamTest.java 
b/src/test/java/org/apache/commons/codec/binary/Base58OutputStreamTest.java
index 3e57569e..abcaf3eb 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base58OutputStreamTest.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base58OutputStreamTest.java
@@ -31,9 +31,9 @@ import org.junit.jupiter.api.Test;
  */
 class Base58OutputStreamTest {
 
-    private static final byte[] CR_LF = {(byte) '\r', (byte) '\n'};
+    private static final byte[] CR_LF = { (byte) '\r', (byte) '\n' };
 
-    private static final byte[] LF = {(byte) '\n'};
+    private static final byte[] LF = { (byte) '\n' };
 
     private void testBase58EmptyOutputStream(final int chunkSize) throws 
Exception {
         final byte[] emptyEncoded = {};
@@ -57,7 +57,6 @@ class Base58OutputStreamTest {
         byte[] decoded = StringUtils.getBytesUtf8("Hello World");
         byte[] encoded = new Base58().encode(decoded);
         testByChunk(encoded, decoded, BaseNCodec.MIME_CHUNK_SIZE, CR_LF);
-
         final BaseNCodec codec = new Base58();
         for (int i = 0; i <= 150; i++) {
             final byte[][] randomData = BaseNTestData.randomData(codec, i);
@@ -72,7 +71,6 @@ class Base58OutputStreamTest {
         byte[] decoded = StringUtils.getBytesUtf8("Hello World");
         byte[] encoded = new Base58().encode(decoded);
         testByteByByte(encoded, decoded, 76, CR_LF);
-
         final BaseNCodec codec = new Base58();
         for (int i = 0; i <= 150; i++) {
             final byte[][] randomData = BaseNTestData.randomData(codec, i);
@@ -89,53 +87,48 @@ class Base58OutputStreamTest {
 
     private void testByChunk(final byte[] encoded, final byte[] decoded, final 
int chunkSize, final byte[] separator) throws Exception {
         ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
-        try (OutputStream out = new Base58OutputStream(byteOut, true)) {
+        try (OutputStream out = 
Base58OutputStream.builder().setOutputStream(byteOut).setEncode(true).get()) {
             out.write(decoded);
         }
         byte[] output = byteOut.toByteArray();
         assertArrayEquals(encoded, output, "Streaming chunked Base58 encode");
-
         byteOut = new ByteArrayOutputStream();
-        try (OutputStream out = new Base58OutputStream(byteOut, false)) {
+        try (OutputStream out = 
Base58OutputStream.builder().setOutputStream(byteOut).setEncode(false).get()) {
             out.write(encoded);
         }
         output = byteOut.toByteArray();
         assertArrayEquals(decoded, output, "Streaming chunked Base58 decode");
-
         byteOut = new ByteArrayOutputStream();
         OutputStream out = byteOut;
         for (int i = 0; i < 10; i++) {
-            out = new Base58OutputStream(out, false);
-            out = new Base58OutputStream(out, true);
+            out = 
Base58OutputStream.builder().setOutputStream(out).setEncode(false).get();
+            out = 
Base58OutputStream.builder().setOutputStream(out).setEncode(true).get();
         }
         out.write(decoded);
         out.close();
         output = byteOut.toByteArray();
-
         assertArrayEquals(decoded, byteOut.toByteArray(), "Streaming chunked 
Base58 wrap-wrap-wrap!");
     }
 
     private void testByteByByte(final byte[] encoded, final byte[] decoded, 
final int chunkSize, final byte[] separator) throws Exception {
         ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
-        try (OutputStream out = new Base58OutputStream(byteOut, true)) {
+        try (OutputStream out = 
Base58OutputStream.builder().setOutputStream(byteOut).setEncode(true).get()) {
             for (final byte element : decoded) {
                 out.write(element);
             }
         }
         byte[] output = byteOut.toByteArray();
         assertArrayEquals(encoded, output, "Streaming byte-by-byte Base58 
encode");
-
         byteOut = new ByteArrayOutputStream();
-        try (OutputStream out = new Base58OutputStream(byteOut, false)) {
+        try (OutputStream out = 
Base58OutputStream.builder().setOutputStream(byteOut).setEncode(false).get()) {
             for (final byte element : encoded) {
                 out.write(element);
             }
         }
         output = byteOut.toByteArray();
         assertArrayEquals(decoded, output, "Streaming byte-by-byte Base58 
decode");
-
         byteOut = new ByteArrayOutputStream();
-        try (OutputStream out = new Base58OutputStream(byteOut, false)) {
+        try (OutputStream out = 
Base58OutputStream.builder().setOutputStream(byteOut).setEncode(false).get()) {
             for (final byte element : encoded) {
                 out.write(element);
                 out.flush();
@@ -143,19 +136,17 @@ class Base58OutputStreamTest {
         }
         output = byteOut.toByteArray();
         assertArrayEquals(decoded, output, "Streaming byte-by-byte flush() 
Base58 decode");
-
         byteOut = new ByteArrayOutputStream();
         OutputStream out = byteOut;
         for (int i = 0; i < 10; i++) {
-            out = new Base58OutputStream(out, false);
-            out = new Base58OutputStream(out, true);
+            out = 
Base58OutputStream.builder().setOutputStream(out).setEncode(false).get();
+            out = 
Base58OutputStream.builder().setOutputStream(out).setEncode(true).get();
         }
         for (final byte element : decoded) {
             out.write(element);
         }
         out.close();
         output = byteOut.toByteArray();
-
         assertArrayEquals(decoded, output, "Streaming byte-by-byte Base58 
wrap-wrap-wrap!");
     }
 
diff --git a/src/test/java/org/apache/commons/codec/binary/Base58Test.java 
b/src/test/java/org/apache/commons/codec/binary/Base58Test.java
index 14975e5d..5be0bf28 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base58Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base58Test.java
@@ -48,7 +48,6 @@ public class Base58Test {
         final byte[] encodedBytes = new 
Base58().encode(StringUtils.getBytesUtf8(content));
         final String encodedContent = StringUtils.newStringUtf8(encodedBytes);
         assertEquals("JxF12TrwUP45BMd", encodedContent, "encoding hello 
world");
-
         final byte[] decodedBytes = new Base58().decode(encodedBytes);
         final String decodedContent = StringUtils.newStringUtf8(decodedBytes);
         assertEquals(content, decodedContent, "decoding hello world");
@@ -60,7 +59,6 @@ public class Base58Test {
         byte[] result = new Base58().encode(empty);
         assertEquals(0, result.length, "empty Base58 encode");
         assertNull(new Base58().encode(null), "empty Base58 encode");
-
         empty = new byte[0];
         result = new Base58().decode(empty);
         assertEquals(0, result.length, "empty Base58 decode");
@@ -68,9 +66,9 @@ public class Base58Test {
     }
 
     @Test
-    void testEncodeDecodeSmall() {
-        for (int i = 0; i < 12; i++) {
-            final byte[] data = new byte[i];
+    void testEncodeDecodeRandom() {
+        for (int i = 1; i < 5; i++) {
+            final byte[] data = new byte[random.nextInt(10000) + 1];
             random.nextBytes(data);
             final byte[] enc = new Base58().encode(data);
             final byte[] dec = new Base58().decode(enc);
@@ -79,9 +77,9 @@ public class Base58Test {
     }
 
     @Test
-    void testEncodeDecodeRandom() {
-        for (int i = 1; i < 5; i++) {
-            final byte[] data = new byte[random.nextInt(10000) + 1];
+    void testEncodeDecodeSmall() {
+        for (int i = 0; i < 12; i++) {
+            final byte[] data = new byte[i];
             random.nextBytes(data);
             final byte[] enc = new Base58().encode(data);
             final byte[] dec = new Base58().decode(enc);
@@ -89,10 +87,25 @@ public class Base58Test {
         }
     }
 
+    @Test
+    void testHexEncoding() {
+        final String hexString = "48656c6c6f20576f726c6421";
+        final byte[] encoded = new 
Base58().encode(StringUtils.getBytesUtf8(hexString));
+        final byte[] decoded = new 
Base58().decode(StringUtils.newStringUtf8(encoded));
+        assertEquals("5m7UdtXCfQxGvX2K9dLrkNs7AFMS98qn8", 
StringUtils.newStringUtf8(encoded), "Hex encoding failed");
+        assertEquals(hexString, StringUtils.newStringUtf8(decoded), "Hex 
decoding failed");
+    }
+
+    @Test
+    void testInvalidCharacters() {
+        // Test decoding with invalid characters (those not in Base58 alphabet)
+        final byte[] invalidChars = "0OIl".getBytes(CHARSET_UTF8); // All 
excluded from Base58
+        assertThrows(IllegalArgumentException.class, () -> new 
Base58().decode(invalidChars));
+    }
+
     @Test
     void testIsInAlphabet() {
         final Base58 base58 = new Base58();
-
         // Valid characters
         for (char c = '1'; c <= '9'; c++) {
             assertTrue(base58.isInAlphabet((byte) c), "char " + c);
@@ -112,13 +125,11 @@ public class Base58Test {
         for (char c = 'm'; c <= 'z'; c++) {
             assertTrue(base58.isInAlphabet((byte) c), "char " + c);
         }
-
         // Invalid characters - excluded from Base58
         assertFalse(base58.isInAlphabet((byte) '0'), "char 0");
         assertFalse(base58.isInAlphabet((byte) 'O'), "char O");
         assertFalse(base58.isInAlphabet((byte) 'I'), "char I");
         assertFalse(base58.isInAlphabet((byte) 'l'), "char l");
-
         // Out of bounds
         assertFalse(base58.isInAlphabet((byte) -1));
         assertFalse(base58.isInAlphabet((byte) 0));
@@ -126,6 +137,19 @@ public class Base58Test {
         assertFalse(base58.isInAlphabet((byte) 255));
     }
 
+    @Test
+    void testLeadingZeros() {
+        // Test that leading zero bytes are encoded as '1' characters
+        final byte[] input = { 0, 0, 1, 2, 3 };
+        final byte[] encoded = new Base58().encode(input);
+        final String encodedStr = new String(encoded);
+        // Should start with "11" (two leading ones for two leading zeros)
+        assertTrue(encodedStr.startsWith("11"), "Leading zeros should encode 
as '1' characters");
+        // Decode should restore the leading zeros
+        final byte[] decoded = new Base58().decode(encoded);
+        assertArrayEquals(input, decoded, "Decoded should match original 
including leading zeros");
+    }
+
     @Test
     void testObjectDecodeWithInvalidParameter() {
         assertThrows(DecoderException.class, () -> new 
Base58().decode(Integer.valueOf(5)));
@@ -135,12 +159,10 @@ public class Base58Test {
     void testObjectDecodeWithValidParameter() throws Exception {
         final String original = "Hello World!";
         final Object o = new Base58().encode(original.getBytes(CHARSET_UTF8));
-
         final Base58 base58 = new Base58();
         final Object oDecoded = base58.decode(o);
         final byte[] baDecoded = (byte[]) oDecoded;
         final String dest = new String(baDecoded);
-
         assertEquals(original, dest, "dest string does not equal original");
     }
 
@@ -153,63 +175,16 @@ public class Base58Test {
     void testObjectEncodeWithValidParameter() throws Exception {
         final String original = "Hello World!";
         final Object origObj = original.getBytes(CHARSET_UTF8);
-
         final Object oEncoded = new Base58().encode(origObj);
         final byte[] bArray = new Base58().decode((byte[]) oEncoded);
         final String dest = new String(bArray);
-
         assertEquals(original, dest, "dest string does not equal original");
     }
 
-    @Test
-    void testLeadingZeros() {
-        // Test that leading zero bytes are encoded as '1' characters
-        final byte[] input = new byte[]{0, 0, 1, 2, 3};
-        final byte[] encoded = new Base58().encode(input);
-        final String encodedStr = new String(encoded);
-
-        // Should start with "11" (two leading ones for two leading zeros)
-        assertTrue(encodedStr.startsWith("11"), "Leading zeros should encode 
as '1' characters");
-
-        // Decode should restore the leading zeros
-        final byte[] decoded = new Base58().decode(encoded);
-        assertArrayEquals(input, decoded, "Decoded should match original 
including leading zeros");
-    }
-
-    @Test
-    void testSingleBytes() {
-        // Test encoding of single bytes
-        for (int i = 1; i <= 255; i++) {
-            final byte[] data = new byte[]{(byte) i};
-            final byte[] enc = new Base58().encode(data);
-            final byte[] dec = new Base58().decode(enc);
-            assertArrayEquals(data, dec, "Failed for byte value: " + i);
-        }
-    }
-
-    @Test
-    void testInvalidCharacters() {
-        // Test decoding with invalid characters (those not in Base58 alphabet)
-        final byte[] invalidChars = "0OIl".getBytes(CHARSET_UTF8); // All 
excluded from Base58
-        assertThrows(IllegalArgumentException.class, () -> new 
Base58().decode(invalidChars));
-    }
-
     @Test
     void testRoundTrip() {
-        final String[] testStrings = {
-                "",
-                "a",
-                "ab",
-                "abc",
-                "abcd",
-                "abcde",
-                "abcdef",
-                "Hello World",
-                "The quick brown fox jumps over the lazy dog",
-                "1234567890",
-                "!@#$%^&*()"
-        };
-
+        final String[] testStrings = { "", "a", "ab", "abc", "abcd", "abcde", 
"abcdef", "Hello World", "The quick brown fox jumps over the lazy dog",
+                "1234567890", "!@#$%^&*()" };
         for (final String test : testStrings) {
             final byte[] input = test.getBytes(CHARSET_UTF8);
             final byte[] encoded = new Base58().encode(input);
@@ -219,13 +194,14 @@ public class Base58Test {
     }
 
     @Test
-    void testHexEncoding() {
-        final String hexString = "48656c6c6f20576f726c6421";
-        final byte[] encoded = new 
Base58().encode(StringUtils.getBytesUtf8(hexString));
-        final byte[] decoded = new 
Base58().decode(StringUtils.newStringUtf8(encoded));
-
-        assertEquals("5m7UdtXCfQxGvX2K9dLrkNs7AFMS98qn8", 
StringUtils.newStringUtf8(encoded), "Hex encoding failed");
-        assertEquals(hexString, StringUtils.newStringUtf8(decoded), "Hex 
decoding failed");
+    void testSingleBytes() {
+        // Test encoding of single bytes
+        for (int i = 1; i <= 255; i++) {
+            final byte[] data = { (byte) i };
+            final byte[] enc = new Base58().encode(data);
+            final byte[] dec = new Base58().decode(enc);
+            assertArrayEquals(data, dec, "Failed for byte value: " + i);
+        }
     }
 
     @Test
@@ -233,23 +209,18 @@ public class Base58Test {
         final String content = "Hello World!";
         final String content1 = "The quick brown fox jumps over the lazy dog.";
         final long content2 = 0x0000287fb4cdL; // Use long to preserve the 
full 48-bit value
-
         final byte[] encodedBytes = new 
Base58().encode(StringUtils.getBytesUtf8(content));
         final byte[] encodedBytes1 = new 
Base58().encode(StringUtils.getBytesUtf8(content1));
-
         final byte[] content2Bytes = 
ByteBuffer.allocate(8).putLong(content2).array();
         final byte[] content2Trimmed = new byte[6];
         System.arraycopy(content2Bytes, 2, content2Trimmed, 0, 6);
         final byte[] encodedBytes2 = new Base58().encode(content2Trimmed);
-
         final String encodedContent = StringUtils.newStringUtf8(encodedBytes);
         final String encodedContent1 = 
StringUtils.newStringUtf8(encodedBytes1);
         final String encodedContent2 = 
StringUtils.newStringUtf8(encodedBytes2);
-
         assertEquals("2NEpo7TZRRrLZSi2U", encodedContent, "encoding hello 
world");
         
assertEquals("USm3fpXnKG5EUBx2ndxBDMPVciP5hGey2Jh4NDv6gmeo1LkMeiKrLJUUBk6Z", 
encodedContent1);
         assertEquals("11233QC4", encodedContent2, "encoding 0x0000287fb4cd");
-
         final byte[] decodedBytes = new Base58().decode(encodedBytes);
         final byte[] decodedBytes1 = new Base58().decode(encodedBytes1);
         final byte[] decodedBytes2 = new Base58().decode(encodedBytes2);
diff --git a/src/test/java/org/apache/commons/codec/binary/Base64Test.java 
b/src/test/java/org/apache/commons/codec/binary/Base64Test.java
index 4a7b66b3..d75589ad 100644
--- a/src/test/java/org/apache/commons/codec/binary/Base64Test.java
+++ b/src/test/java/org/apache/commons/codec/binary/Base64Test.java
@@ -60,6 +60,7 @@ class Base64Test {
      * Example test cases with valid characters but impossible combinations of
      * trailing characters (i.e. cannot be created during encoding).
      */
+    // @formatter:off
     static final String[] BASE64_IMPOSSIBLE_CASES = {
         "ZE==",
         "ZmC=",
@@ -67,11 +68,13 @@ class Base64Test {
         "Zm9vYmC=",
         "AB",
     };
+    // @formatter:on
 
     /**
      * Copy of the standard base-64 encoding table. Used to test decoding the 
final
      * character of encoded bytes.
      */
+    // @formatter:off
     private static final byte[] STANDARD_ENCODE_TABLE = {
             'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
             'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
@@ -79,6 +82,7 @@ class Base64Test {
             'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
             '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
     };
+    // @formatter:on
 
     /**
      * Test base 64 decoding of the final trailing bits. Trailing encoded bytes
@@ -611,8 +615,8 @@ class Base64Test {
             "Zm9vYmF-",
             "Zm9vYmF_"
     })
-    void testDecodeEncodeUrlSafeByteArray(final String encodedText) {
-        final String decodedText = 
StringUtils.newStringUsAscii(Base64.decodeBase64UrlSafe(encodedText.getBytes(CHARSET_UTF8)));
+    void testDecodeEncodeUrl(final String encodedText) {
+        final String decodedText = 
StringUtils.newStringUsAscii(Base64.decodeBase64UrlSafe(encodedText));
         final String encodedText2 = 
Base64.encodeBase64URLSafeString(StringUtils.getBytesUtf8(decodedText));
         assertEquals(encodedText, encodedText2);
     }
@@ -630,8 +634,8 @@ class Base64Test {
             "Zm9vYmF-",
             "Zm9vYmF_"
     })
-    void testDecodeEncodeUrl(final String encodedText) {
-        final String decodedText = 
StringUtils.newStringUsAscii(Base64.decodeBase64UrlSafe(encodedText));
+    void testDecodeEncodeUrlSafeByteArray(final String encodedText) {
+        final String decodedText = 
StringUtils.newStringUsAscii(Base64.decodeBase64UrlSafe(encodedText.getBytes(CHARSET_UTF8)));
         final String encodedText2 = 
Base64.encodeBase64URLSafeString(StringUtils.getBytesUtf8(decodedText));
         assertEquals(encodedText, encodedText2);
     }

Reply via email to