티스토리 뷰

Programming/JAVA

BASE64 인코딩 디코딩

다루사무 2014. 12. 18. 17:42
반응형
public static String base64Encode(String str)  throws java.io.IOException {
  if ( str == null || str.equals("") ) {
     return "";
  } else {
     sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
     byte[] b1 = str.getBytes();
     String result = encoder.encode(b1);
     return result;
  }
}

public static String base64Decode(String str)  throws java.io.IOException {
  if ( str == null || str.equals("") ) {
     return "";
  } else {
     sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
     byte[] b1 = decoder.decodeBuffer(str);
     String result = new String(b1);
     return result;
  }
}

base64Encode("인코딩할 문자");
base64Decode("디코딩할 문자");

'Programming > JAVA' 카테고리의 다른 글

json-lib 2.3과 필요 의존 라이브러리  (0) 2018.11.06
JEUS , WebtoB 기본  (0) 2015.01.02
자바로 경고창 띄우기  (0) 2014.01.07
여러모로 사용되는 정규표현식!  (0) 2014.01.06
"==" 과 "equals()" 의 차이점  (0) 2013.09.06
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함