With the increased use of SOA, there are times when we need to encode the data to support Transport Layer Security. This can be achieved with Java.

I am providing a sample use case scenario, which converts a given string to its equivalent Base64 encoded String and than decodes it back to the original String.


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

 * Encode - Decode a String using Java
public class JavaEncordingExample{

    public static void main(String args[]) throws IOException {
        String orig = "www.javagenious.com";

        //Encode the string to base64        
		byte[] encoded = Base64.encodeBase64(orig.getBytes());      
        System.out.println("Input: " + orig );
        System.out.println("Base64 Output : " + new String(encoded));
		// Decode the string        
		byte[] decoded = Base64.decodeBase64(encoded);       
        System.out.println("Base 64 Decoded  String : " + new String(decoded));


Enter your email address:

Delivered by FeedBurner

Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)