zoukankan      html  css  js  c++  java
  • 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);                
        }
    }

    运行结果如下:

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

  • 相关阅读:
    dos命令连接mysql并且查看编码方式
    node.js 好博客
    node.js 连接数据库
    express的基本配置项
    express 手册
    VPS巴士
    nodejs书籍
    nodejs connect模块
    网站工具,如天气,手机归属地
    NodeJS的异步编程风格
  • 原文地址:https://www.cnblogs.com/rick168/p/4650674.html
Copyright © 2011-2022 走看看