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);                
    }
}

 

运行结果如下:
Java中使用BASE64加密&解密

 

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

相关文章:

  • 2022-12-23
  • 2021-09-24
  • 2021-07-10
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
猜你喜欢
  • 2021-10-01
  • 2021-08-14
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
相关资源
相似解决方案