- 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 data = BASE64.encryptBASE64("http://aub.iteye.com/".getBytes());
- System.out.println("加密后:"+data);
- byte[] byteArray = BASE64.decryptBASE64(data);
- System.out.println("解密后:"+new String(byteArray));
- }
- }
java base64加密算法
最新推荐文章于 2021-10-11 13:44:44 发布