package com.tu.Security;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class Base64 {

	public static void main(String[] args) {
		jdkBase64("comtu");
		commonsCodesBase64("comtu");
		bouncyCastleBase64("comtu");
	}

	public static void jdkBase64(String msg) {
		try {
			BASE64Encoder encoder = new BASE64Encoder();
			String encode = encoder.encode(msg.getBytes());
			System.out.println("encode:" + encode);
			
			BASE64Decoder decoder = new BASE64Decoder();
			byte[] b = decoder.decodeBuffer(encode);
			System.out.println("decoder:" + new String(b));
		} catch (Exception e) {
		}
	}

	public static void commonsCodesBase64(String msg) {
		byte[] encodeBytes = org.apache.commons.codec.binary.Base64.encodeBase64(msg.getBytes());
		System.out.println("encode:" + new String(encodeBytes));

		byte[] decodeBytes = org.apache.commons.codec.binary.Base64.decodeBase64(encodeBytes);
		System.out.println("decode:" + new String(decodeBytes));
	}
	
	public static void bouncyCastleBase64(String msg) {
		byte[] encodeBytes = org.bouncycastle.util.encoders.Base64.encode(msg.getBytes());
		System.out.println("encode:" + new String(encodeBytes));
		
		byte[] decodeBytes = org.bouncycastle.util.encoders.Base64.decode(encodeBytes);
		System.out.println("decode:" + new String(decodeBytes));
	}
	

}





























