How do I decode a Base64 encoded binary?

Category: commons.codec, viewed: 5754 time(s).
package org.kodejava.example.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
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Uncensored Newsgroups
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Java Training

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats