import java.io.IOException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class BASE64Coding {
private static BASE64Encoder encoder = new sun.misc.BASE64Encoder();
private static BASE64Decoder decoder = new sun.misc.BASE64Decoder();
public BASE64Coding() {
}
public static String encode(String s) {
return encoder.encode(s.getBytes());
}
public static String decode(String s) {
try {
byte[] temp = decoder.decodeBuffer(s);
return new String(temp);
} catch (IOException ioe) {
// handler
}
return s;
}
/**
* @param args
*/
public static void main(String[] args) {
String str = "13516741234";
System.out.println("加密");
System.out.println(BASE64Coding.encode(str));
System.out.println("解密");
System.out.println(BASE64Coding.decode(BASE64Coding.encode(str)));
}
}
java下的Base64编解码示例(1)
最新推荐文章于 2024-08-10 04:12:52 发布