• Java中使用BASE64加密&解密


    package com.bao.tools.encryption;

    import java.io.IOException;

    import org.junit.Test;

    import sun.misc.BASE64Decoder;
    import sun.misc.BASE64Encoder;

    /**
     * @title BASE64加密&解密
     * @description
     * 邮件,HTTP协议,一般用户名及密码
     * @author Administrator
     * @date 2015-7-16
     */
    public class CBase64 {
        /**
         * 加密
         * BASE64Encoder类
         */
        public static String setEncrypted(String value){
            if(value==null)return null;
            return new BASE64Encoder().encodeBuffer(value.getBytes());
        }
        /**
         * 解密
         * BASE64Decoder类
         * @throws IOException
         */
        public static String getEncrypted(String value) throws IOException{
            if(value==null)return null;
            BASE64Decoder d = new BASE64Decoder();
            byte[] b = d.decodeBuffer(value);
            return new String(b);
            
        }
        
        /*
         * 测试
         */
        @Test
        public void test() throws IOException {
            String name = "李u2";
            String hide = setEncrypted(name);
            String open = getEncrypted(hide);

            System.out.println("------BASE64编码与解码-------");
            System.out.println("元字符为:"+name);
            System.out.println("编 码 :"+hide);
            System.out.println("解 码 :"+open);                
        }
    }

    运行结果如下:

    个人见解:该加密算法安全系数相对比较低,相对于要求安全度高的信息不建议采用该方法 。

  • 相关阅读:
    linux 网络性能优化
    select/poll/epoll原理探究及总结
    linux socket读数据错误解释
    linux 单机跨进程通信
    map与hash_map使用与对比
    python web自动化测试框架搭建(功能&接口)——环境搭建
    Jenkins构建触发器的区别
    python改变导入模块中的变量的问题
    Jmeter断言中判断请求失败的响应代码问题
    Jmeter中动态获取jsessionid来登录
  • 原文地址:https://www.cnblogs.com/rick168/p/4650674.html
Copyright © 2020-2023  润新知