package org.kodejava.commons.codec;
import org.apache.commons.codec.binary.Base64;
import java.util.Arrays;
public class Base64Decode {
public static void main(String[] args) {
String hello = "SGVsbG8gV29ybGQ=";
// Decode a previously encoded string using decodeBase64 method and
// passing the byte[] of the encoded string.
byte[] decoded = Base64.decodeBase64(hello.getBytes());
// Print the decoded array
System.out.println(Arrays.toString(decoded));
// Convert the decoded byte[] back to the original string and print
// the result.
String decodedString = new String(decoded);
System.out.println(hello + " = " + decodedString);
}
}
The result of our code is:
[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]
SGVsbG8gV29ybGQ= = Hello World
Maven Dependencies
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.16.0</version>
</dependency>
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024