1. java.util.Base64 (jdk 8+) 사용


import java.io.UnsupportedEncodingException;

import java.util.Base64;

import java.util.Base64.Decoder;

import java.util.Base64.Encoder;


public class Base64Example {

public static void main(String[] args) throws UnsupportedEncodingException {

Encoder encoder = Base64.getEncoder();

Decoder decoder = Base64.getDecoder();

String text = "Hello World!";

byte[] textByte = text.getBytes("UTF-8");

byte[] encTextByte = encoder.encode(textByte);

byte[] decTextByte = decoder.decode(encTextByte);

System.out.println("encTextByte = "+new String(encTextByte));

System.out.println("decTextByte = "+new String(decTextByte,"UTF-8"));

}


2. Apache Commons Codec (org.apache.commons.codec.binary.Base64) 사용


+ Recent posts