base 64文字列と通常文字列との変換

1016 ワード


import java.io.IOException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class Base64String
{

	/**base64              
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException
	{
		//base64  
		String utf8string1 = "        ";
		System.out.println("utf8string1 =" +utf8string1);
		BASE64Encoder bASE64Encoder = new BASE64Encoder();
		String base64string = bASE64Encoder.encode(utf8string1.getBytes("UTF-8"));
		System.out.println("base64string = "+base64string);
		//base64  
		BASE64Decoder  bASE64Decoder  = new BASE64Decoder();
		byte[] bt = bASE64Decoder.decodeBuffer("5a2X56ym5Liy5LmL6Ze055qE6L2s5o2i");
		String utf8String2 = new String(bt,"UTF-8");
		System.out.println("utf8String2 = "+ utf8String2);
	}

}