EncrytTool.java 3.56 KB
Newer Older
hulei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
package com.sstf.tool;

import com.brilliance.esb.core.util.CryptoUtil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.concurrent.atomic.AtomicInteger;

public class EncrytTool extends JFrame  {
    JPanel center =new JPanel();
    public EncrytTool()throws IOException {
        init();
        this.setVisible(true);
    }
    private void init(){
        this.setSize(800,600);
        this.setTitle("sql加密");
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(null);           //设置为空布局
        this.setResizable(false);

//        JLabel jl=new JLabel();
//

        Font font=new Font("微软雅黑",Font.BOLD,15);
        JTextArea  jl= new JTextArea();
        jl.setBounds(10,300,600,300);
       // let the text pane know this is what you want
        jl.setEditable(false); // as before
//        jl.setBackground(null); // this is the same as a JLabel
        jl.setBorder(null); // remove the border
        jl.setLineWrap(true);
        jl.setFont(font);

//        jl.set
        JTextArea jtf =new JTextArea();   //文本框
        jtf.setBounds(10,10,600,200);
        jtf.setLineWrap(true);
        jtf.setWrapStyleWord(true);
        jtf.setFont(font);
        JButton jb=new JButton("加密");        //鼠标单击监听器
        jb.setBounds(610,10,60,30);
        jb.addActionListener(
                (ActionListener) ->{
                    String text =jtf.getText();
                    List<String> lines = Arrays.asList(text.split(";"));

                    List<String> allLines = new ArrayList<>();

                    lines.stream().filter(line->!line.trim().isEmpty())
                            .forEach(line->{
                                String newline = line.replace('\uFEFF',' ').trim();
                                String aesLine = CryptoUtil.encrypt(newline,"AES");
                                allLines.add(newline);
                                allLines.add(aesLine);
                            });


                    StringJoiner sj = new StringJoiner("\r\n");
                    AtomicInteger index = new AtomicInteger();

                    allLines.forEach((line)->{
                        System.out.println(line);
                        System.out.println();
                        sj.add(line);
                        sj.add("");
                        index.incrementAndGet();

                        if(index.intValue() % 2 == 0){
                            String hline="--------------------------------------------------------------------------------------------------";
                            System.out.println(hline);
                            sj.add(hline);
                        }

                    });
                    jl.setText( sj.toString());
                });
//        jtf.addActionListener((ActionEvent e)->{    //常用键enter  用addActionListener
//            jb.doClick();
//        });

//
        JScrollPane jpl=  new JScrollPane(jl);
        jpl.setBounds(10,300,600,300);
        JScrollPane jpf=  new JScrollPane(jtf);
        jpf.setBounds(10,10,600,200);
//
        this.add(jpl);
        this.add(jpf);
        this.add(jb);



    }

    public static void main(String[] args) {
        try {
            EncrytTool encrytTool=new EncrytTool();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}