Java Base64 加密解密
发布时间:2016-02-20 18:00:10
使用JDK的类 BASE64Decoder BASE64Encoder Java代码 package test; import sun.misc.BASE64Decoder; import ...
使用JDK的类 BASE64Decoder BASE64Encoder
Java代码
- package test;
-
- import sun.misc.BASE64Decoder;
- import sun.misc.BASE64Encoder;
-
- /**
- * BASE64加密解密
- */
- public class BASE64
- {
-
- /**
- * BASE64解密
- * @param key
- * @return
- * @throws Exception
- */
- public static byte[] decryptBASE64(String key) throws Exception {
- return (new BASE64Decoder()).decodeBuffer(key);
- }
-
- /**
- * BASE64加密
- * @param key
- * @return
- * @throws Exception
- */
- public static String encryptBASE64(byte[] key) throws Exception {
- return (new BASE64Encoder()).encodeBuffer(key);
- }
-
- public static void main(String[] args) throws Exception
- {
- String para = "{\"IdList1\": 1,\"IdList2\": [1,2,3,4,5,6,18],\"IdList3\": [1,2]}";
- String data = BASE64.encryptBASE64(para.getBytes());
- System.out.println("加密前:"+data);
-
- byte[] byteArray = BASE64.decryptBASE64(data);
- System.out.println("解密后:"+new String(byteArray));
- }
- }
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:Java Base64 加密解密
关键词:JAVA
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。