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

    package Base64;
    import javax.swing.*;


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

    /**
    * @author Miracle Luna
    * @version 1.0
    * @date 2019/7/3 18:55
    */
    public class Base64Converter {

    final static Base64.Encoder encoder = Base64.getEncoder();
    final static Base64.Decoder decoder = Base64.getDecoder();

    /**
    * 给字符串加密
    * @param text
    * @return
    */
    public static String encode(String text) {
    byte[] textByte = new byte[0];
    try {
    textByte = text.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    }
    String encodedText = encoder.encodeToString(textByte);
    return encodedText;
    }

    /**
    * 将加密后的字符串进行解密
    * @param encodedText
    * @return
    */
    public static String decode(String encodedText) {
    String text = null;
    try {
    text = new String(decoder.decode(encodedText), "UTF-8");
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    }
    return text;
    }

    public static void main(String[] args) throws UnsupportedEncodingException {

    String username = "Miracle Luna";
    String password = "p@sSW0rd";

    // 加密
    System.out.println("==== [加密后] 用户名/密码 =====");
    System.out.println(Base64Converter.encode(username));
    System.out.println(Base64Converter.encode(password));

    // 解密
    System.out.println(" ==== [解密后] 用户名/密码 =====");
    System.out.println(Base64Converter.decode(Base64Converter.encode(username)));
    System.out.println(Base64Converter.decode(Base64Converter.encode(password)));
    }
    }

    package Base64;

    import javax.swing.JFrame;
    import javax.swing.WindowConstants;

    public class JFrameDemo {

    public void CreateJFrame() {
    JFrame jf = new JFrame("这是一个JFrame窗体"); // 实例化一个JFrame对象
    jf.setVisible(true); // 设置窗体可视
    jf.setSize(50, 35); // 设置窗体大小
    jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // 设置窗体关闭方式
    }

    public static void main(String[] args) {
    new JFrameDemo().CreateJFrame(); // 调用CreateJFrame()方法
    }

    }

  • 相关阅读:
    前端资料
    贪心
    二叉树的最大深度
    最长回文子串
    动态规划-tsp
    动态规划
    spfa与SLF和LLL(复习)
    动态规划之最长 公共子序列和上升子序列
    最近最远距离之暴力优化
    基于Element-UI封装的季度插件
  • 原文地址:https://www.cnblogs.com/wrx166/p/14161941.html
Copyright © 2011-2022 走看看