webservices中需要将声明为byte[]的类型进行base64编码传输
在传输大量业务数据的String和图片时可以采用,而且避免明文传输带来的风险
public static String encodeBASE64(String s) {
if (s == null)
return null;
return (new sun.misc.BASE64Encoder()).encode(s.getBytes());
}
public static String decodeBASE64(String s) {
if (s == null)
return null;
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b);
} catch (Exception e) {
return null;
}
}