@Override
    public int invoke(ToolInvocation invocation) {
        try {
            var arguments  = invocation.arguments();
            var fromBase   = Integer.parseInt(CliUtils.optionOrThrow(arguments, FROM_OPTION));
            var toBase     = Integer.parseInt(CliUtils.optionOrThrow(arguments, TO_OPTION));
            // We cap the input length since non-base(16|64) transforms are O(n^2) and we don't want
            // to risk melting someone's CPU by them piping something large into the process by accident.
            byte[] inBytes = invocation.stdIn().readAllBytes();
            if (inBytes.length > MAX_IN_BYTES) {
                throw new IllegalArgumentException("Input size is too large (%d), max is %d"
                                                   .formatted(inBytes.length, MAX_IN_BYTES));
            }
            var inString = fromUtf8Bytes(inBytes).strip(); // We ignore whitespace to avoid trailing \n issues
            byte[] decoded = switch (fromBase) {
                case 16 -> unhex(inString);
                case 58 -> Base58.codec().decode(inString);
                case 62 -> Base62.codec().decode(inString);
                case 64 -> Base64.getUrlDecoder().decode(inString);
                default -> throw new IllegalArgumentException("Unsupported from-base: %d".formatted(fromBase));
            };
            String encoded = switch (toBase) {
                case 16 -> hex(decoded);
                case 58 -> Base58.codec().encode(decoded);
                case 62 -> Base62.codec().encode(decoded);
                case 64 -> Base64.getUrlEncoder().withoutPadding().encodeToString(decoded);
                default -> throw new IllegalArgumentException("Unsupported to-base: %d".formatted(toBase));
            };
            invocation.stdOut().println(encoded);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
        return 0;
    }
Simple tool to convert between different Base N encodings, for a fixed set of N.

@author vekterli
vespaclient-java/src/main/java/com/yahoo/vespa/security/tool/crypto/ConvertBaseTool.java