프로그래밍/JAVA

base64 사용법

GANADARA 2018. 7. 19. 21:53

public static void base64() { 

String text = "ktko"

byte[] targetBytes = text.getBytes();

 // Base64 인코딩 /////////////////////////////////////////////////// 

Encoder encoder = Base64.getEncoder(); 

byte[] encodedBytes = encoder.encode(targetBytes); 

// Base64 디코딩 /////////////////////////////////////////////////// 

Decoder decoder = Base64.getDecoder(); 

byte[] decodedBytes = decoder.decode(encodedBytes); 

System.out.println("인코딩 전 : " + text); 

System.out.println("인코딩 text : " + new String(encodedBytes)); 

System.out.println("디코딩 text : " + new String(decodedBytes)); 

}