> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/spring/concepts-set-3/encoding-or-decoding/base-encoding/base32/encoding-and-decoding-in-java.md).

# Encoding and Decoding in Java

## About

Java provides support for Base32 encoding and decoding through third-party libraries like Apache Commons Codec. The standard Java library (`java.util.Base64`) does not include Base32, so an external library is typically used.

## Maven POM Dependency

### Apache Commons Codec

```xml
<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.15</version>
</dependency>
```

## Encoding Example

```java
package com.org.example;

import org.apache.commons.codec.binary.Base32;

public class Application {

    public static void main(final String[] args) {

        Base32 base32 = new Base32();
        String originalString = "Hello, World!";
        byte[] encodedBytes = base32.encode(originalString.getBytes());
        
        String encodedString = new String(encodedBytes);
        
        System.out.println("Encoded String: " + encodedString);
    }
}
```

<figure><img src="/files/O49E8z5rE2lMtO9AqjdF" alt="" width="560"><figcaption></figcaption></figure>

## Decoding Example

```java
import org.apache.commons.codec.binary.Base32;

@SpringBootApplication
public class Application {

    public static void main(final String[] args) {
        Base32 base32 = new Base32();
        String encodedString = "JBSWY3DPEB3W64TMMQ======";
        byte[] decodedBytes = base32.decode(encodedString);

        String decodedString = new String(decodedBytes);

        System.out.println("Decoded String: " + decodedString);
    }
}
```

<figure><img src="/files/UEl1bsXkO7ln9l8STnlX" alt="" width="560"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/spring/concepts-set-3/encoding-or-decoding/base-encoding/base32/encoding-and-decoding-in-java.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
