[BASE64] BASE64 인코딩

프로그래밍/Library 2009. 2. 27. 15:03 Posted by galad
// Encode the bytes of the string
String encoding = new sun.misc.BASE64Encoder().encodeBuffer(userPassword.getBytes());
// Set the "Authorization" request property for the URLConnection
// chuck로 인한 줄바꿈 문자 삭제. PW가 길면 문제.
uc.setRequestProperty("Authorization","Basic " + encoding.substring(0, encoding.length() - 2)); 


import org.apache.commons.codec.binary.Base64;

// false - chunk하지 않는다(chuck하면 76자 단위로 줄바꿈)
String encoding = new String(Base64.encodeBase64(userPassword.getBytes(), false));
uc.setRequestProperty("Authorization","Basic " + encoding);

둘 중에 하나 쓰면 됨.
아래 것은 라이브러리 받아야 한다.