简单的文件数据加密器的实现
来源:互联网 发布:淘宝致一科技真的吗 编辑:程序博客网 时间:2024/06/05 16:04
由于经常有人用本人电脑,一些重要的机密文件不免被人看见,所以自己写了小的加密文件数据的小工具。此加密工具采用的是最简单的加密方法:把数据分别异或得出加密后的文件;
操作步骤:
源代码:
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.swing.*;
public class ToolsTakePassword extends JFrame ...{
private static final long serialVersionUID = 1L;
private JFileChooser jf;
private JMenuBar jmb;
private JMenu file;
private JMenuItem open;
private JMenuItem save;
private JMenuItem exit;
private JTextArea text;
private JScrollPane jsp;
private JPanel p;
private JButton takepassword;
private JCheckBox override;
private JLabel intru;
private JLabel currentfile;
private JLabel currentfilename;
private Font ft;
private boolean flag = true;
private File filesave = null;
private File newfilesave = null;
private JTextField codenum;
private JProgressBar jbr;
private int code;
private JButton refresh;
private JLabel inputcode;
private JLabel temp0;
private JLabel temp1;
public ToolsTakePassword() ...{
super("--文件加密器-- 作者:sharpyuce.");
jf = new JFileChooser();
jmb = new JMenuBar();
file = new JMenu("File");
open = new JMenuItem("Open");
save = new JMenuItem("Save");
exit = new JMenuItem("Exit");
text = new JTextArea();
jsp = new JScrollPane(text);
p = new JPanel();
codenum = new JTextField(5);
codenum.setText("50");
refresh = new JButton("刷新");
takepassword = new JButton("加 密");
override = new JCheckBox();
intru = new JLabel("是否覆盖原文件");
currentfile = new JLabel("当前文件:");
currentfilename = new JLabel("");
temp0 = new JLabel(" ");
temp1 = new JLabel(" ");
inputcode = new JLabel("输入加密码(输入一个整数值):");
this.init();
this.setSize(800, 600);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@SuppressWarnings("unused")
private void init() ...{
open.addActionListener(new ActionListener() ...{
public void actionPerformed(ActionEvent e) ...{
text.setText("");
new Open().start();
}
});
file.add(open);
file.add(save);
exit.addActionListener(new ActionListener()...{
public void actionPerformed(ActionEvent e) ...{
System.exit(0);
}
});
file.add(exit);
jmb.add(file);
this.add(jmb, BorderLayout.NORTH);
this.add(jsp, BorderLayout.CENTER);
takepassword.addActionListener(new ActionListener() ...{
public void actionPerformed(ActionEvent e) ...{
new TakePassWord().start();
}
});
p.add(inputcode);
p.add(codenum);
p.add(temp0);
refresh.addActionListener(new ActionListener()...{
public void actionPerformed(ActionEvent e) ...{
text.setText("");
new Refresh().start();
}
});
p.add(refresh);
p.add(temp1);
p.add(takepassword);
override.addItemListener(new ItemListener()...{
public void itemStateChanged(ItemEvent e) ...{
flag =!flag;
}
});
p.add(override);
p.add(intru);
p.add(currentfile);
p.add(currentfilename);
this.add(p, BorderLayout.SOUTH);
refresh.setFont(ft);
takepassword.setFont(ft);
intru.setFont(ft);
file.setFont(ft);
save.setFont(ft);
open.setFont(ft);
exit.setFont(ft);
currentfile.setFont(ft);
currentfilename.setFont(ft);
inputcode.setFont(ft);
}
class Open extends Thread...{
public void run()...{
jf.showOpenDialog(null);
filesave = jf.getSelectedFile();
currentfilename.setText(filesave.getAbsolutePath());
InputStream fis = null;
byte[] buff = new byte[1024];
try ...{
fis=new FileInputStream(filesave);
while (fis.available() > 0) ...{
int len = fis.read(buff);
String s = new String(buff, 0, len);
text.append(s);
}
} catch (IOException e1) ...{
e1.printStackTrace();
} finally ...{
if (fis != null) ...{
try ...{
fis.close();
} catch (IOException e1) ...{
e1.printStackTrace();
}
}
}
}
}
class TakePassWord extends Thread...{
public void run()...{
code = Integer.parseInt(codenum.getText().trim());
String s = text.getText();
String[] ss = s.split(" ");
FileOutputStream fr = null;
if(flag)...{
jf.showSaveDialog(null);
newfilesave = jf.getSelectedFile();
currentfilename.setText(newfilesave.getAbsolutePath());
}
try ...{
if (flag) ...{
fr = new FileOutputStream(newfilesave);
filesave = newfilesave;
} else ...{
fr = new FileOutputStream(filesave);
currentfilename.setText(filesave.getAbsolutePath());
}
for (String t : ss) ...{
byte[] buff = t.getBytes();
String n = " ";
for (int i = 0; i < buff.length; i++) ...{
fr.write(buff[i] ^ code);
}
fr.write(n.getBytes());
}
} catch (IOException e1) ...{
e1.printStackTrace();
} finally ...{
if (fr != null) ...{
try ...{
fr.close();
} catch (IOException e1) ...{
e1.printStackTrace();
}
}
}
}
}
class Refresh extends Thread...{
public void run()...{
InputStream fis = null;
byte[] buff = new byte[1024];
try ...{
fis=new FileInputStream(filesave);
while (fis.available() > 0) ...{
int len = fis.read(buff);
String s = new String(buff, 0, len);
text.append(s);
}
} catch (IOException e1) ...{
e1.printStackTrace();
} finally ...{
if (fis != null) ...{
try ...{
fis.close();
} catch (IOException e1) ...{
e1.printStackTrace();
}
}
}
}
}
public static void main(String[] args) ...{
new ToolsTakePassword();
}
}
如果想要生成EXE文件:先下载jsmooth,使用这个工具可 制作exe程序
Skeleton Chooser下拉框中选择Windowed Wrapper Skeleton Properties : 在launch java app in the exe process 选项打勾 4. 点击Executable, 这一步是设置生成的exe文件的属性,包括名字,图标,路径 5. 设置完成后,继续下一选项,Application.Main class : 主运行类,有main()方法的类 Embedded jar : 就是选择你要制作成EXE文件的jar 5. 其他的选项如果不需要可不必设置,最后单击project下的compile 就OK了 , 可以在装有jre的机器上直接运行。
- 简单的文件数据加密器的实现
- 加密文件简单的实现
- 简单的文件加密
- 文件的简单加密
- 简单的文件加密
- 简单加密的实现
- 实现简单的数据加密-可直接引用
- 使用IO实现对文件简单的加密
- 简单的加密解密文件
- 简单的文件加密示例
- 简单的文件加密解密
- 简单信息的加密实现
- playfair加密的简单实现
- 实现简单的文本加密
- Md5加密的简单实现
- 数据加密与解密的简单原理
- 简单的数据加密与解密
- [Android]网络数据的简单加密
- 操作系统基础
- [读书笔记]欧几里得算法的解释
- 关于LOGFONT
- 使用存储过程 操作数据库 2个输入参数 1个输出参数
- .NET Framework/.NET Compact Framework/.NET Micro Framework功能集比较
- 简单的文件数据加密器的实现
- 全面解析ASP.NET2.0下的URL重写
- HTML标记属性
- 我用Java实现的二叉树的遍历(递归和非递归)
- 33条C#、.Net经典面试题目及答案
- Dis# v3.1.1
- 判断单向链表中是否有环
- 一个简单文本操作
- C#中获取程序当前路径