import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; /** * Created by Administrator on 2017/11/22 0022. */ public class Base64Utils { public static String encodeBase64(String s){ Object retObj= null; try { byte[] input = s.getBytes(); Class clazz=Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64"); Method mainMethod= clazz.getMethod("encode", byte[].class); mainMethod.setAccessible(true); retObj = mainMethod.invoke(null, new Object[]{input}); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return (String)retObj; } /*** * decode by Base64 */ public static String decodeBase64(String input) { Object retObj= null; try { Class clazz=Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64"); Method mainMethod= clazz.getMethod("decode", String.class); mainMethod.setAccessible(true); retObj = mainMethod.invoke(null, input); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return new String((byte[])retObj); } }
Base64工具类,Base64Utils
最新推荐文章于 2025-10-13 08:15:44 发布
本文介绍了一个Java实现的Base64编码和解码工具类。该工具使用了Apache Xerces库来完成Base64的编码和解码工作,并提供了简单的API供开发者调用。
2777

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



