Base64加密和解密使用

Base64加密

这个加密是固定加密,有些不安全,拿到加密串可以解密了

直接上代码:

package com.zjy.knife4j.controller;

import java.io.UnsupportedEncodingException;
import java.util.Base64;

public class Test2 {
    
    

    public static void main(String[] args) throws UnsupportedEncodingException {
    
    
        // base64加密
        String encode = Base64.getEncoder().encodeToString("王中王火腿肠".getBytes("UTF-8"));
        String encode2 = Base64.getEncoder().encodeToString("中王".getBytes("UTF-8"));
        System.out.println(encode);
        System.out.println(encode2);
        // base64解密
        byte[] decode = Base64.getDecoder().decode(encode);
        byte[] decode2 = Base64.getDecoder().decode(encode2);
        
        System.out.println(new String(decode, "UTF-8"));
        System.out.println(new String(decode2, "UTF-8"));
    }
}

控制台打印

在这里插入图片描述

这个打印结果,不管执行几次都是加密成相同的字符串,只要拿到加密字符串,直接调用解密方法就可以拿到原始数据了。极度不安全!
可以根据自己业务需求选择性使用!

欢迎大神指导,可以留言交流!

======================
本人原创文章,转载注明出入!

=================

猜你喜欢

转载自blog.csdn.net/dayonglove2018/article/details/107897710
今日推荐