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;
}
}
本文介绍了一种用于WebServices的数据传输方式,通过Base64编码将字符串和图片等byte[]类型的数据进行编码和解码,以确保数据的安全传输并避免明文传输的风险。
382

被折叠的 条评论
为什么被折叠?



