zoukankan      html  css  js  c++  java
  • java Base64加密解密

    package com.zhaochao.utill;
    import java.io.UnsupportedEncodingException;
    import java.lang.reflect.Method;
    
    public class Base64Utill {
        public static String encode(String code) throws UnsupportedEncodingException, Exception {
            return encodeBase64(code.getBytes());
        }
    
        public static String decode(String code) throws UnsupportedEncodingException, Exception {
            return new String(decodeBase64(code));
        }
    
        public static String encodeBase64(byte[] input) throws Exception {
            Class clazz = Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64");
            Method mainMethod = clazz.getMethod("encode", byte[].class);
            mainMethod.setAccessible(true);
            Object retObj = mainMethod.invoke(null, new Object[] { input });
            return (String) retObj;
        }
    
        public static byte[] decodeBase64(String input) throws Exception {
            Class clazz = Class.forName("com.sun.org.apache.xerces.internal.impl.dv.util.Base64");
            Method mainMethod = clazz.getMethod("decode", String.class);
            mainMethod.setAccessible(true);
            Object retObj = mainMethod.invoke(null, input);
            return (byte[]) retObj;
        }
    
        public static void main(String[] rags) throws UnsupportedEncodingException, Exception {
            String str = "abadjfajerjaqwrasdf";
            String code = Base64Utill.encode(str);
            System.err.println("加密前:" + str);
            System.err.println("加密后:" + code);
            System.err.println("解密后:" + Base64Utill.decode(code));
    
        }
    
    }
  • 相关阅读:
    apipost如何设置断言
    接口文档生成详细教程
    接口测试的时候如何生成随机数据进行测试
    armbian用户指南
    仿「ONE · 一个」 的微信小程序
    [armbian_ubuntu] 设置中文环境
    realtek wifi驱动
    armbian 入门知识基础学习
    [Armbian] armbian-config设置
    内存型号介绍
  • 原文地址:https://www.cnblogs.com/azhqiang/p/5505340.html
Copyright © 2011-2022 走看看