Thursday, June 2, 2016

Base 64 Encoding and Decoding

Base 64 Encoding and Decoding

// jar needed - common-codec-1.10.jar

package com.test;

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


public class Base64Test {

 public static void main(String[] args) {
 // encode data using BASE64
 byte[]   bytesEncoded = Base64.encodeBase64("userid:password".getBytes());
 System.out.println("encoded value is " + new String(bytesEncoded ));

 // Decode data by processing encoded data
 byte[] valueDecoded= Base64.decodeBase64(bytesEncoded );
 System.out.println("Decoded value is " + new String(valueDecoded));
 }
}

No comments:

Post a Comment