使用jframe编写一个base64加密解密工具
该工具可以使用exe4j来打包成exe工具(如何打包自己百度)
先上截图功能
运行main方法后,会弹出如下窗口
输入密文
然后点击解密,在点格式化
代码分享
package tools;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import org.apache.commons.codec.binary.Base64;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
/** TODO(用一句话描述这个类做什么用)。
*
* <pre>
* 构建组:toJar
* 作者:chenrd
* 邮箱:1658219123@qq.com
* 日期:2019-3-7-下午3:06:58
* 版权:个人所有
* </pre>
* Base64 加密解密工具
*/
public class ChenrdBase64 extends JFrame {
private static final long serialVersionUID = 1L;
Base64 base64 = new Base64();
JPanel desktop = new JPanel();
JPanel jfr1 = new JPanel();
JPanel btnAllPanel = new JPanel();
JButton incodeBtn = new JButton("加密");
JButton decodeBtn = new JButton("解密");
JButton formatBtn = new JButton("格式化");
JTextArea inputMsg = new JTextArea("",30,50);
public ChenrdBase64() {
super("base64-chenrd");
this.add(desktop);
this.setBounds(0, 0, 900, 600);
this.setLocationRelativeTo(null);
//关闭该窗口的时候不用关闭主窗口,所以要注释下行代码
// this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//按平台默认的方式把添加的窗口有序的排列,不然子窗口挡住了父窗口
this.setLocationByPlatform(true);
this.setVisible(true);
init();
}
public void init() {
inputMsg.setLineWrap(true);//激活自动换行功能
inputMsg.setWrapStyleWord(true);//激活断行不断字功能
JScrollPane js = new JScrollPane(inputMsg);
jfr1.setLayout(new BorderLayout());
jfr1.add(js,BorderLayout.NORTH);
//设置组件垂直排列
// btnAllPanel.setLayout(new BoxLayout(btnAllPanel, BoxLayout.X_AXIS));
btnAllPanel.add(incodeBtn);
btnAllPanel.add(decodeBtn);
btnAllPanel.add(formatBtn);
jfr1.add(btnAllPanel,BorderLayout.SOUTH);
desktop.add(jfr1, 0);
// 换行
inputMsg.setSelectedTextColor(Color.BLUE);
// 激活自动换行功能
inputMsg.setLineWrap(true);
// 激活断行不断字功能
inputMsg.setWrapStyleWord(true);
//给按钮添加点击事件
incodeBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String msg = inputMsg.getText();
inputMsg.setText(new String(Base64.encodeBase64(msg.getBytes("utf-8"))));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
}
});
//给按钮添加点击事件
decodeBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String msg = inputMsg.getText();
try {
inputMsg.setText(new String(base64.decode(msg.getBytes("utf-8"))));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
}
});
//给按钮添加点击事件
formatBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 格式化输出格式(使用dom4j格式化)
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("utf-8");
StringWriter writer = new StringWriter();
// 格式化输出流
XMLWriter xmlWriter = new XMLWriter(writer, format);
// 将document写入到输出流
try {
String text = inputMsg.getText();
Document doc = DocumentHelper.parseText(text);
xmlWriter.write(doc);
inputMsg.setText(writer.toString());
System.out.println(writer.toString());
xmlWriter.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
}
public static void main(String[] args) {
ChenrdBase64 my64 = new ChenrdBase64();
my64.validate();//刷新所有子组件
}
}
使用jframe编写一个base64加密解密工具的更多相关文章
- Base64加密解密工具类
使用Apache commons codec类Base64进行加密解密 maven依赖 <dependency> <groupId>commons-codec</grou ...
- Base64加密解密原理以及代码实现(VC++)
Base64加密解密原理以及代码实现 转自:http://blog.csdn.net/jacky_dai/article/details/4698461 1. Base64使用A--Z,a--z,0- ...
- password学3——Java BASE64加密解密
Base64是网络上最常见的用于传输8Bit字节代码的编码方式之中的一个,大家能够查看RFC2045-RFC2049.上面有MIME的具体规范.Base64编码可用于在HTTP环境下传递较长的标识信息 ...
- Java android DES+Base64加密解密
服务器与客户端加密解密传输, 中间遇到各种坑,客户端无论用AES还是DES解密时都会出现错误,后来才看到好多人说要用AES/DES加完密后还要BASE64加密,照做时发现android和java的Ba ...
- django删除表重建&修改用户密码&base64加密解密字符串&ps aux参数说明&各种Error例子
1.django的queryset不支持负索引 AssertionError: Negative indexing is not supported. 2.django向前端JavaScript传递列 ...
- Java语言实现 Base64 加密 & 解密
Java语言实现 Base64 加密 & 解密 Base64是网络上最常见的用于传输8Bit字节码的编码方式之一,Base64就是一种基于64个可打印字符来表示二进制数据的方法. Base64 ...
- JS实现base64加密解密
JS实现base64加密解密 转载自http://blog.csdn.net/fengzheng0306/archive/2006/04/25/676055.aspx 方法一: <HTML> ...
- 【代码笔记】iOS-3DES+Base64加密解密
一,工程目录. 二,代码. RootViewController.m #import "RootViewController.h" #import "NSString+T ...
- 实现Base64加密解密
using System; using System.Text; namespace Common { /// <summary> /// 实现Base64加密解密 /// </ ...
随机推荐
- ubuntu安装cocos2dx
操作系统:ubuntu16.04 LTSIDE:Code::blocks 16.01Cocos2dx版本:cocos2d-x 3.11.1这篇随笔将会简要地演示如何在ubuntu下安装cocos2dx ...
- sklearn参数优化方法
学习器模型中一般有两个参数:一类参数可以从数据中学习估计得到,还有一类参数无法从数据中估计,只能靠人的经验进行指定,后一类参数就叫超参数 比如,支持向量机里的C,Kernel,gama,朴素贝叶斯里的 ...
- Phoenix系列:二级索引(1)
Phoenix使用HBase作为后端存储,对于HBase来说,我们通常使用字典序的RowKey来快速访问数据,除此之外,也可以使用自定义的Filter来搜索数据,但是它是基于全表扫描的.而Phoeni ...
- ubuntu如何设置开机启动默认命令行界面
图形模式下,首先进入终端: 1. 运行 sudo vi/etc/default/grub 2. 找到 GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash” 3.改为 GR ...
- Entity Framework Core的坑:Skip/Take放在Select之前造成Include的实体全表查询
今天将一个迁移至 ASP.NET Core 的项目放到一台 Linux 服务器上试运行.站点启动后,浏览器打开一个页面一直处于等待状态.接着奇怪的事情发生了,整个 Linux 服务器响应缓慢,ssh命 ...
- okvis代码解读
okvis_timing模块 提供时间转换的功能函数 okvis_util模块 包含 assert_macros.hpp 该文件包含一些有用的断言宏. source_file_pos.hpp 该文件 ...
- 在链表中,元素的"位序"概念淡化,结点的"位置"概念淡化
在链表中,元素的"位序"概念淡化,结点的"位置"概念淡化 1 结点的描述与实现 C语言中用带指针的结构体类型来描述 typedef struct Lnode { ...
- [network] IPVS / Load balancer / Linux Virtual Server
Load Balancer IPVS: http://kb.linuxvirtualserver.org/wiki/IPVS NAT: http://kb.linuxvirtualserver.org ...
- nodejs prefix(全局)和cache(缓存)windows下设置
引:在安装完nodejs后,通过npm下载全局模块默认安装到{%USERDATA%}C:\Users\username\AppData\下的Roaming\npm下,这当然是不太对的默认. 1,安装L ...
- spring quartz动态修改执行时间
1.获取schedule <bean name="startQuartz" lazy-init="false" autowire="no&quo ...