Base64加密解密算法 java代码实现
import org.apache.commons.codec.binary.Base64;
public class Base64Demo01 {
public static void main(String[] args) {
//对内容进行加密
String s="123456";
//byte[] buf=Base64.encodeBase64(s.getBytes());
String result=Base64.encodeBase64String(s.getBytes());
System.out.println(result);//MTIzNDU2
//对内容进行解密
byte[] buf= Base64.decodeBase64(result);
System.out.println(new String(buf));
}
public static void main(String[] args) {
//对内容进行加密
String s="123456";
//byte[] buf=Base64.encodeBase64(s.getBytes());
String result=Base64.encodeBase64String(s.getBytes());
System.out.println(result);//MTIzNDU2
//对内容进行解密
byte[] buf= Base64.decodeBase64(result);
System.out.println(new String(buf));
}
}