IT
[Java] 자바 Base64 인코딩 / 디코딩
정미나
2010. 10. 29. 15:32
* base64Encode
* base64Decode
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;
}
}
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;
}
}
* base64Decode
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;
}
}
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;
}
}